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
22 lines (16 loc) · 739 Bytes
/
plot2.R
File metadata and controls
22 lines (16 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Read data
set <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", colClasses = "character")
# Get column names
cols <- colnames(set)
# Create "DateTime" column with combination of date and time
set$DateTime <- strptime(paste(set$Date, set$Time), format = "%d/%m/%Y %H:%M:%S", tz = "UTC")
# Set data types
set$Date <- as.Date(set$Date, "%d/%m/%Y")
set$Global_active_power <- as.numeric(set$Global_active_power)
# Subset data set to the 2 relevant dates
set <- subset(set, set$Date %in% as.Date(c("2007-02-01", "2007-02-02")))
# Create plot
with(set, plot(DateTime, Global_active_power, type = "l", xlab = "", ylab = "Global Active Power (kilowatts)"))
# Save as PNG
dev.copy(png, file = "plot2.png")
dev.off()