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
27 lines (15 loc) · 941 Bytes
/
Copy pathplot1.R
File metadata and controls
27 lines (15 loc) · 941 Bytes
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
plot1 <- function(){
## Read in the data from the data set the separator is specified as ; and the
## NA values are defined as ?
data<-read.table("household_power_consumption.txt",header=TRUE, sep=";", na.strings="?")
## Merge time and date together and convert to timestamp
data$timestamp<-strptime(paste(data$Date,data$Time), format="%d/%m/%Y%H:%M:%S")
## Subset the data to chose only the two days of interest
data <- subset(data, timestamp >= "2007-02-01" & timestamp <= "2007-02-02")
## Open the PNG device to write write the graph into
png(filename = "plot1.png", width = 480, height = 480, units = "px")
## Create the histogram with
hist(data$Global_active_power, col = "red", main="Global Active Power", xlab="Global Active Power (kilowatts)")
## Close the device and return to standard device
dev.off()
}