forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
24 lines (13 loc) · 965 Bytes
/
Copy pathplot1.R
File metadata and controls
24 lines (13 loc) · 965 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# read in the complete household_power_consumption.txt file
inputTable <- read.table("household_power_consumption.txt",comment.char="", sep = ";", header=TRUE, stringsAsFactors=FALSE, na.string = "?")
# create a new column that combines Date and Time columns
inputTable$DateTime <- paste(inputTable$Date, inputTable$Time, sep= " ")
inputTable$DateTime <- strptime(inputTable$DateTime, format = "%d/%m/%Y %H:%M:%S")
# create a new data table of data that is on 2007-02-01 and 2007-02-02
# this is used to create the data plots
subsetFrame <- subset(inputTable, as.Date(inputTable$Date, format = "%d/%m/%Y") >= "2007-02-01" & as.Date(inputTable$Date, format = "%d/%m/%Y") <= "2007-02-02")
# The first plot is of Global_active_power vs date (histogram)
png(filename = "plot1.png",
width = 480, height = 480, units = "px")
hist(subsetFrame$Global_active_power, col="red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)")
dev.off()