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
42 lines (31 loc) · 1.3 KB
/
Copy pathplot4.R
File metadata and controls
42 lines (31 loc) · 1.3 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
# Project 1
#
# set working dir
setwd("C:/Users/masak_000/SkyDrive/Documents/cousera/exdata/Project1")
# set a file name which is loaded
filepath <- ("./data.txt")
# load data
x <- read.table(filepath, sep=";", header=TRUE, na.strings="?")
x$datetime <- strptime(paste(x$Date, x$Time), "%d/%m/%Y %H:%M:%S")
a <- subset(x, as.Date(x$datetime) %in% c(as.Date("2007-02-01"), as.Date("2007-02-02")))
# Making graph on the screen
par(mfrow = c(2, 2))
with(a, {
# Graph 1
plot(datetime, Global_active_power, xlab="",ylab="Global Active Power (kilowatts)", type="l")
# Graph 2
plot(datetime,Voltage, xlab="datetime",ylab="Voltage", type="l")
# Graph 3
with(a, {
plot(datetime, Sub_metering_1, xlab="",ylab="Energy sub melering", type = "n")
lines(datetime, Sub_metering_1, col="black")
lines(datetime, Sub_metering_2, col="red")
lines(datetime, Sub_metering_3, col="blue")
})
legend("topright", col = c("black", "red", "blue"), legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"), lty="solid", bty = "n")
# Graph 4
plot(datetime, Global_reactive_power, xlab="datetime",ylab="Global_reactive_power", type="l", xaxp=c(0, 6, 0.5))
})
# Copy to png file
dev.copy(png, file = "plot3.png", width=480, height=480)
dev.off()