forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlot4.R
21 lines (21 loc) · 1.61 KB
/
Plot4.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
library(dplyr)
library(lubridate)
electricity<-read.csv("household_power_consumption.txt",header = TRUE, sep=";")
electricity$Date<-paste(electricity$Date,electricity$Time)
electricity<-mutate(electricity,Date=as.POSIXct(Date,format="%d/%m/%Y %H:%M:%OS"))
electricity <- subset( electricity, select = -Time )
small_electricity<-filter(electricity,year(electricity$Date)==2007 & month(electricity$Date)==02 & (day(electricity$Date)==01| day(electricity$Date)==02))
small_electricity$Voltage <- sub(",",".",small_electricity$Voltage)
small_electricity$Voltage<-as.numeric(small_electricity$Voltage)
small_electricity$Global_reactive_power <- sub(",",".",small_electricity$Global_reactive_power)
small_electricity$Global_reactive_power<-as.numeric(small_electricity$Global_reactive_power)
png(filename="Plot4.png",width = 480, height = 480)
par(mfrow=c(2,2))
plot(small_electricity$Date,small_electricity$Global_active_power,type = 'l',ylab= "Global Active Power",xlab = '')
plot(small_electricity$Date,small_electricity$Voltage,type = 'l',ylab= "Voltage",xlab = 'datetime')
plot(small_electricity$Date,small_electricity$Sub_metering_1,type = 'l',col= 'black', ylab= "Energy devSub Metering",xlab = '')
lines(small_electricity$Date,small_electricity$Sub_metering_2,type = 'l',col= 'red',xlab = '')
lines(small_electricity$Date,small_electricity$Sub_metering_3,type = 'l',col= 'blue',xlab = '')
legend("topright",bty="n", c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),lty=c(1,1,1),col=c("black","red","blue"))
plot(small_electricity$Date,small_electricity$Global_reactive_power,type = 'l',ylab= "Global_reactive_power",xlab = 'datetime')
dev.off()