forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot3.R
28 lines (25 loc) · 1.27 KB
/
plot3.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
plot3 <- function () {
# load the data for 1-2 Feb 2007
pc1 <- loadPCdays()
# create the plot on a transparant background (is in the example provided)
par (bg='transparent', cex=0.75, omi=c(0, 0.05, 0, 0))
plot (pc1$DateTime, pc1$Sub_metering_1, type= 'n', ylab='Energy sub metering', xlab='')
points (pc1$DateTime, pc1$Sub_metering_1, type = 'l', col='black' )
points (pc1$DateTime, pc1$Sub_metering_2, type = 'l', col='red' )
points (pc1$DateTime, pc1$Sub_metering_3, type = 'l', col='blue' )
# set the legend with 'text.with' to get the full text within the legend
legend ('topright', lty=1, col = c('black', 'red', 'blue'),
legend= c('Sub_metering_1','Sub_metering_2','Sub_metering_3' ),
text.width = 42000, y.intersp=1.5)
# copy to the png file with the same size as the example provided
dev.copy(png, file = "plot3.png")
dev.off()
}
loadPCdays <- function () {
pc0 <<- read.csv('household_power_consumption.txt', sep=';', na.strings='?')
# select the rows for Feb 1-2, 2007
pc1 <- pc0[(pc0$Date=='1/2/2007')|(pc0$Date=='2/2/2007'),]
#add DateTime column
pc1$DateTime = strptime(paste (pc1$Date,pc1$Time, sep=' '), "%d/%m/%Y %H:%M:%S", tz='')
pc1
}