forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
24 lines (21 loc) · 1.18 KB
/
Copy pathplot2.R
File metadata and controls
24 lines (21 loc) · 1.18 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
## Exploratory Data Analysis Project 1
## Global active power in time
## plot2.R -------> plot2.png
## Load data file and convert Date and time objects
powerdata<- read.csv("household_power_consumption.txt", sep=";",
colClasses = c("character", "character","numeric","numeric","numeric",
"numeric","numeric","numeric","numeric"),
na.strings = "?")
powerdata$Time <- strptime(paste(powerdata$Date, powerdata$Time), "%d/%m/%Y %H:%M:%S")## keep #Var at 9
powerdata$Date <- as.Date(powerdata$Date, "%d/%m/%Y")
## Create a data subset for the require time frame
Dates <- as.Date(c("2007-02-01", "2007-02-02"), "%Y-%m-%d")
pdata_subset <- subset(powerdata, Date %in% Dates)
## Date and Time and change date format
pdata_subset$Datetime <- as.POSIXct(pdata_subset$Time) ## subset aditional var for clarity
## Save plot in png format
png("plot2.png" , width = 480, height = 480) ## notice that dates are in french
## Create plot Global Active Power vs Time
plot(pdata_subset$Datetime, pdata_subset$Global_active_power, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
dev.off()