forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
21 lines (12 loc) · 840 Bytes
/
plot2.R
File metadata and controls
21 lines (12 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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 2
png(filename = "plot2.png", width = 480, height = 480)
with(selected_power_consumption, plot(Date_Time, Global_active_power, type = "l", ylab = "Global Active Power (kilowatts)", xlab = ""))
dev.off()