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
18 lines (16 loc) · 736 Bytes
/
plot1.R
File metadata and controls
18 lines (16 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
library(data.table)
# Read the whole dataset into pc_data.
# Keep only the following two dates, "1/2/2007" and "2/2/2007".
# Convert the Date column to IDate class and Time column to ITime class.
pc_data <- fread("household_power_consumption.txt", sep = ";", na.strings = "?")
pc_data <- subset(pc_data, Date %in% c("1/2/2007", "2/2/2007"))
pc_data[,Date:=as.IDate(Date, format = "%d/%m/%Y")]
pc_data[,Time:=as.ITime(Time, format = "%H:%M:%S")]
# Plot histogram of variable "Global_active_power" and save to a png file.
png("plot1.png", bg = "transparent")
with(pc_data,
hist(Global_active_power, breaks = 12,
col = "red", main = "Global Active Power",
xlab = "Global Active Power (kilowatts)")
)
dev.off()