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
19 lines (15 loc) · 821 Bytes
/
plot2.R
File metadata and controls
19 lines (15 loc) · 821 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# the dataset so large, just select the parts that are needed.
sub_pc <- read.delim('household_power_consumption.txt',
sep=';',header=TRUE, nrows = 700000, na.strings='?')
sub_pc$Date <- as.Date(sub_pc$Date, '%d/%m/%Y')
pdata <- subset.data.frame(sub_pc, Date >= as.Date('2007-02-01') &
Date <= as.Date('2007-02-02'))
pdata$Global_active_power <- as.numeric(pdata$Global_active_power)
library(dplyr)
pdata2 <- mutate(pdata, Ftime =as.POSIXct(paste(Date, Time)),.before=Global_active_power)
pdata2 <- pdata2[complete.cases(pdata2), ] # remove the incomplete rows.
# create a png file for the plot2.
png(filename='plot2.png', width=480, height=480)
with(pdata2, plot(Global_active_power~Ftime, type='s',
xlab='', ylab='Global Active Power(kilowatts)' ))
dev.off()