forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
40 lines (32 loc) · 1.24 KB
/
plot4.R
File metadata and controls
40 lines (32 loc) · 1.24 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
filePath <- '../../household_power_consumption.txt'
data <- read.table(filePath, header=TRUE, sep=";", na.strings="?" )
data <- subset(data,
as.Date(Date, format="%d/%m/%Y") >= as.Date('2007-02-01')
& as.Date(Date, format = "%d/%m/%Y") <= as.Date('2007-02-02'))
data$datetime <- strptime(paste(data$Date, data$Time), "%e/%m/%Y %H:%M:%S")
png(filename="plot4.png",
width=480, height=480,
units="px", bg = "transparent");
par(mfrow = c(2, 2))
plot(data$datetime, data$Global_active_power, type='l',
ylab = "Global Active Power",
xlab = "",
main = "")
plot(data$datetime, data$Voltage, type='l',
ylab = "Voltage",
xlab = "datetime",
main = "")
plot(data$datetime, data$Sub_metering_1, type='l',
col = "black",
ylab = "Energy sub metering",
xlab = "",
main = "")
points(data$datetime, data$Sub_metering_2, type='l', col="red")
points(data$datetime, data$Sub_metering_3, type='l', col="blue")
legend("topright", bty = "n", legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
col=c("black", "red", "blue"), lwd=1)
plot(data$datetime, data$Global_reactive_power, type='l',
ylab = "Global_reactive_power",
xlab = "datetime",
main = "")
dev.off()