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 (21 loc) · 772 Bytes
/
Copy pathplot1.R
File metadata and controls
24 lines (21 loc) · 772 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
## script to create first plot for assignment
## output file is a histogram titled plot1.png
## read data
df <- read.table("household_power_consumption.txt",
sep = ";",
header = TRUE,
stringsAsFactors = FALSE,
na.strings = "?",
colClasses = c(rep("character", 2), rep("double", 7)))
## only need data from 2007-02-01 to 2007-02-02
df$Date <- as.Date(df$Date, format = "%d/%m/%Y")
epower <- df[(as.Date("2007-02-01") <= df$Date &
df$Date <= as.Date("2007-02-02")),]
## plot
png(file= "plot1.png", height = 480, width = 480)
hist(epower$Global_active_power,
breaks = 12,
col = "red",
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)")
dev.off()