forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot 3.R
More file actions
25 lines (20 loc) · 1.3 KB
/
plot 3.R
File metadata and controls
25 lines (20 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
25
# Download and unzip file
fileUrl<-"https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(fileUrl,destfile="./hhpowerconsumption.zip")
unzip("./hhpowerconsumption.zip")
# Read in text file, but just for 2 day period in February. Add column names
power<-read.table("./household_power_consumption.txt",skip=66637,nrows=2880, header=F,sep=";",na.string=c("?"), comment.char="")
colnames(power)<-read.table("./household_power_consumption.txt",nrows=1,header=F,sep=";")
# Convert date to date type, then paste date and time variables together
power$Date2<-as.Date(power$Date,"%d/%m/%Y")
power$date_time<-strptime(paste(power$Date2, power$Time),"%Y-%m-%d %H:%M:%S")
#with(power, plot(date_time, Sub_metering_1, Sub_metering_2, Sub_metering_3, type='l'))
with(power, plot(date_time, Sub_metering_1, type = "l", ylab = "Energy sub metering", xlab=""))
with(power, lines(date_time, Sub_metering_2, col="red"))
with(power, lines(date_time, Sub_metering_3, col="blue"))
legend(x="topright", c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), col= c('black', 'red', 'blue'),
pch= '-')
# Save as png file
setwd("C:/Users/jdole/OneDrive - Research Triangle Institute/Related to R/Coursera/Exploratory Data Analysis")
dev.copy(png, file= 'plot3.png', width=480, height=480)
dev.off()