forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
49 lines (39 loc) · 1.28 KB
/
plot4.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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#Load data (It is created in create_data.R)
econsumption<-readRDS("econsumption.rds")
#Change Region (I have spanish weekdays)
Sys.setlocale("LC_TIME", "English")
#Create plot
png(file="plot4.png")
#Set global par
par(mfrow=c(2,2))
#Create first plot
with(econsumption,
plot(DateTime,Global_active_power,
type="l",
ylab="Global Active Power",
xlab=""))
#Create second plot
with(econsumption,
plot(DateTime,Voltage,
type="l",
ylab="Voltage",
xlab="datetime"))
#Create third plot
plot(rep(econsumption$DateTime,3),
c(econsumption$Sub_metering_1,econsumption$Sub_metering_2,econsumption$Sub_metering_3),type="n",
xlab="",
ylab="Energy sub metering")
points(econsumption$DateTime,econsumption$Sub_metering_1,col="black",type="l")
points(econsumption$DateTime,econsumption$Sub_metering_2,col="red",type="l")
points(econsumption$DateTime,econsumption$Sub_metering_3,col="blue",type="l")
legend("topright",legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),
col=c("black","red","blue"),
lty = "solid",
bty="n")
#Create fourth plot
with(econsumption,
plot(DateTime,Global_reactive_power,
type="l",
ylab="Global_reactive_power",
xlab="datetime"))
dev.off()