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
15 lines (15 loc) · 996 Bytes
/
plot3.R
File metadata and controls
15 lines (15 loc) · 996 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url, destfile="data.zip", method="curl")
unzip("data.zip")
df <- read.csv("household_power_consumption.txt", sep=";", stringsAsFactors = F, header = F, skip=66637, nrows=2880, na.strings="?")
df_header <- read.csv("household_power_consumption.txt", sep=";", stringsAsFactors = F, header = T, nrows=1)
colnames(df) <- colnames(df_header)
df$Date <- strptime(paste(df$Date, df$Time), format="%d/%m/%Y %H:%M:%S")
df <- df[,names(df) != "Time"]
colnames(df)[1] <- "Date_time"
png(filename="plot3.png", width=480, height=480, units="px", bg="transparent")
plot(df$Date_time, df$Sub_metering_1, xlab="", ylab="Energy sub metering", type="l", col="black")
lines(df$Date_time, df$Sub_metering_2, col="red")
lines(df$Date_time, df$Sub_metering_3, col="blue")
legend('topright', legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty=c(1,1,1), col=c("black", "red", "blue"))
dev.off()