forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
20 lines (12 loc) · 848 Bytes
/
plot1.R
File metadata and controls
20 lines (12 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#reads the data to dataframe
power_consumption_data <- read.table(file = "household_power_consumption.txt", header = TRUE, sep = ";", na.strings = "?")
#convert date and time columns
power_consumption_data$Date_Time <- with(power_consumption_data, paste(Date, Time))
power_consumption_data$Date_Time <- strptime(power_consumption_data$Date_Time, format = "%d/%m/%Y %T")
selected_date_string <- c("2007-02-01", "2007-02-02")
selected_power_consumption <- subset(power_consumption_data, strftime(Date_Time, format = "%Y-%m-%d") %in% selected_date_string)
selected_power_consumption <- droplevels(selected_power_consumption)
#plot 1
png(filename = "plot1.png", width = 480, height = 480)
with(selected_power_consumption, hist(Global_active_power, col = "red", xlab = "Global Active Power (kilowatts)", main = "Global Active Power"))
dev.off()