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
44 lines (34 loc) · 1.42 KB
/
Copy pathplot4.R
File metadata and controls
44 lines (34 loc) · 1.42 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
library(sqldf)
# read file and convert data and time columns
file <- "household_power_consumption.txt"
power <- read.csv.sql(file, sql = "select * from file where Date in ('1/2/2007', '2/2/2007')", sep =";" )
closeAllConnections()
png(file = "plot4.png", width = 480, height = 480)
par(mfrow = c(2,2))
#create upper left
plot(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Global_active_power,
xlab = "",
ylab = "Global Active Power (kilowatts)",
type = "l")
#create upper right
plot(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Voltage,
xlab = "datetime",
ylab = "Voltage",
type = "l")
#create plot lower left
plot(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Sub_metering_1,
col = "black",
xlab = "",
ylab = "Energy sub metering",
type = "l")
lines(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Sub_metering_2,
col = "red")
lines(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Sub_metering_3,
col = "blue")
legend("topright", bty = "n", col = c("black", "red", "blue"), lty= 1, legend = names(power[7:9]))
#create lower right
plot(as.POSIXct(paste(power$Date, power$Time), format = "%d/%m/%Y%H:%M:%S"), power$Global_reactive_power,
xlab = "datetime",
ylab = "Global_reactive_power",
type = "l")
dev.off()