-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
67 lines (46 loc) · 1.74 KB
/
plot4.R
File metadata and controls
67 lines (46 loc) · 1.74 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# get Data
source("load_myData.R")
myData_TwoDaysPeriod <- load_myData()
# Plots Constants
PlotWidth <- 480
PlotHeight <- 480
PlotUnits <- "px"
PlotBg <- "white"
PlotFileName <- "./data/plot4.png"
MarginBottom <- 8
MarginLeft <- 8
MarginTop <- 7
MarginRight <- 6
PlotLinesColor2 <- "blue"
PlotLinesColor <- "red"
PlotColsColor <- "black"
PlotTitle <- "Global Active Power"
PlotXLabel <- ""
PlotYLabel <- "Energy sub metering"
#Graphical Device is PNG
png(filename = PlotFileName , width = PlotWidth, height = PlotHeight, units = PlotUnits, bg = PlotBg)
#Graphic with 2 lnes and two columns
par(mfrow=c(2,2))
# Graphic 1 Plot
plot(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Global_active_power,
type="l",
xlab="",
ylab="Global Active Power")
# Graphic 2 Plot
plot(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Voltage, type="l",
xlab="datetime", ylab="Voltage")
# Graphic 3 Plot
plot(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Sub_metering_1, col = PlotColsColor,
type="l",
xlab=PlotXLabel,
ylab=PlotYLabel)
lines(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Sub_metering_2, col=PlotLinesColor)
lines(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Sub_metering_3, col=PlotLinesColor2)
legend("topright",col=c("black", "red", "blue"), c("Sub_metering_1",
"Sub_metering_2", "Sub_metering_3"), lty=1)
# Graphic 4 Plot
plot(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Global_reactive_power, type="n",
xlab="datetime", ylab="Global_reactive_power")
lines(myData_TwoDaysPeriod$DateTime, myData_TwoDaysPeriod$Global_reactive_power)
# Close Graphical device
dev.off()