forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot3.R
26 lines (21 loc) · 1.17 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
# Begin by reading in the data from a file in your working directory.
TooMuchData <- read.table(file="./household_power_consumption.txt", sep=";",
header = TRUE, na.strings = "?", nrows=70000)
# Subset the data and remove the large data frame for memory conservation
TooMuchData$Date <- as.Date(TooMuchData$Date, format = "%d/%m/%Y" )
data <- TooMuchData[which(TooMuchData$Date =="2007-02-01"
| TooMuchData$Date =="2007-02-02"),]
rm(TooMuchData)
#========================Plot 3=================================================
# Create PNG output device, create the plot, overlay 2 other "lines" and legend
# and close device.
png(filename="plot3.png", width=480, height=480, units = "px")
par(bg="transparent")
plot(data$Sub_metering_1, type="l", xaxt="n", xlab="",
ylab="Energy sub metering", bg="transparent")
axis(1, at=c(0, 1440, 2880), labels = c("Thu", "Fri", "Sat"))
lines(data$Sub_metering_2, col="red")
lines(data$Sub_metering_3, col="blue")
legend(x="topright", legend=c(names(data)[7:9]),
col=c("black", "red", "blue"), lty=1)
dev.off()