-
Notifications
You must be signed in to change notification settings - Fork 56.7k
/
Copy pathplot2.R
21 lines (18 loc) · 932 Bytes
/
plot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#Course Project 1
#loading and getting the data
data_raw <- read.table("household_power_consumption.txt", skip = 1,sep = ";",
na.strings = "?")
names(data_raw) <- c("Date","Time", "Global_active_power",
"Global_reactive_power", "Voltage", "Global_intensity",
"Sub_metering_1", "Sub_metering_2", "Sub_metering_3")
data_raw <- subset(data_raw, data_raw$Date=="1/2/2007" | data_raw$Date =="2/2/2007")
#change format of time data
Sys.setlocale("LC_TIME", "English")
date_format <- as.Date(data_raw$Date, format = "%d/%m/%Y")
time_format <- strptime(data_raw$Time, format = "%H:%M:%S")
time_final <- as.POSIXct(paste(date_format, data_raw$Time))
#plotting(2)
plot(time_final, data_raw$Global_active_power, xlab = "", ylab = "Global Active Power (kilowatts)", type = "l")
#copy the graphic to the file
dev.copy(png, file = "plot2.png")
dev.off()