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
24 lines (17 loc) · 770 Bytes
/
plot2.R
File metadata and controls
24 lines (17 loc) · 770 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Read in the table
hpc <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", na.strings = "?")
# Create a new Date-Time field
hpc$datetime <- paste(hpc$Date, hpc$Time)
# Convert the Date field as a Date class
hpc$Date <- dmy(hpc$Date)
lo <- hpc$Date == as.Date("2007-02-01") | hpc$Date == as.Date("2007-02-02")
# Subset the data as required
hpc_data <- subset(hpc, lo)
# Convert the datetime field as a Time class
hpc_data$datetime <- dmy_hms(hpc_data$datetime)
# Open a png graphic device
png(filename = "plot2.png", height = 480, width = 480)
# Plot the graph
with(hpc_data, plot(datetime, Global_active_power, type = "o", pch = ".", xlab = "", ylab = "Global Active Power (kilowatts)"))
# Close the device
dev.off()