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
18 lines (13 loc) · 699 Bytes
/
plot2.R
File metadata and controls
18 lines (13 loc) · 699 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#Read the whole csv file into R
data = read.csv("household_power_consumption.txt",sep = ";")
#Subset the dataset to the dates 2007-02-01 and 2007-02-02 only
Data$Date<- as.Date(data$Date, "%d/%m/%Y")
usefulData <- subset(data, data$Date == as.Date("2007-02-02") | data$Date == as.Date("2007-02-01"))
#Change the Time column format to PODIXlt
usefulData$Time<- strptime(paste(usefulData$Date, usefulData$Time), format = "%Y-%m-%d %H:%M:%S")
#Launch a PNG graphics device
png(filename = "plot2.png",width = 480,height = 480)
#Generate the plot
plot(usefulData$Time,usefulData$Global_active_power, type = "l", ylab = "Global Active Power (kilowatts)", xlab = "")
#Close graphics device
dev.off()