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
19 lines (19 loc) · 1.07 KB
/
plot2.R
File metadata and controls
19 lines (19 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
plot2 <- function ( ) {
## Set to the correct working directory
setwd("~/Desktop/Exploratory Data Analysis/Project 1")
## Read household_power_consumption.txt data
powerData <- read.csv("household_power_consumption.txt",header=TRUE,sep=";",na.strings = "?", colClasses = "character")
## Clean up data, by fixing data and time format and subsetting only the dates to analyze
powerData$Date <- as.Date(powerData$Date, format="%d/%m/%Y")
powerData$Time <- as.POSIXct(powerData$Time,format="%H:%M:%S")
smallPowerData <- subset(powerData,subset=(Date < "2007-02-03"))
smallPowerData <- subset(smallPowerData, subset=(Date > "2007-01-31"))
## Create a graph ..Thurs, Fri, Sat on x for Global Active Power (kilowatts) on y
plot(smallPowerData$Global_active_power,type="l",axes = FALSE,ylab="Global Active Power (kilowatts)",xlab="datetime")
axis(side = 1, at = c(0,1500,2881), c("Thu", "Fri", "Sat"))
axis(side = 2, at = c(0,2,4,6), c(0,2,4,6))
## Copy plot to png
dev.copy(png, file = "plot2.png")
## Close connection
dev.off()
}