forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
24 lines (24 loc) · 1.3 KB
/
plot3.R
File metadata and controls
24 lines (24 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
## Loading the dplyr library
library(dplyr)
## Loading the file
household <- read.csv("household_power_consumption.txt", header=TRUE, sep=";")
## Select only the dates we are interested in
householdSub <- filter(household, Date=="1/2/2007" | Date=="2/2/2007")
## Formatting the dates
householdSub <- mutate(householdSub, DateTime = as.POSIXct(paste(Date, Time), format = '%d/%m/%Y %H:%M:%S'))
## Converting the factors as numerics
householdSub <- mutate(householdSub, Sub_metering_1 = as.numeric(as.character(householdSub$Sub_metering_1)))
householdSub <- mutate(householdSub, Sub_metering_2 = as.numeric(as.character(householdSub$Sub_metering_2)))
householdSub <- mutate(householdSub, Sub_metering_3 = as.numeric(as.character(householdSub$Sub_metering_3)))
## Create the file to draw in
png(file = "plot3.png", width = 480, height = 480)
## Setting the background color as transparent
par("bg"= "transparent")
## Drawing the plot
with(householdSub, plot(DateTime, Sub_metering_1, type="l", xlab="", ylab="Energy sub metering"))
with(householdSub, (lines(DateTime, Sub_metering_2, col="red")))
with(householdSub, (lines(DateTime, Sub_metering_3, col="blue")))
## Adding the legend box
legend("topright", lty=1, col=c("black","red","blue"), legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
## Closing the device
dev.off()