forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
19 lines (16 loc) · 787 Bytes
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
library(downloader)
library(lubridate)
zip_file <- "exdata%2Fdata%2Fhousehold_power_consumption.zip"
data_file <- "household_power_consumption.txt"
if (!file.exists(data_file)){
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download(url, dest=zip_file, mode="wb")
unzip (zip_file)
file.remove(zip_file)
}
epc <- read.table(data_file, header=TRUE, sep=";", na.strings = "?")
epc$Datetime <- dmy_hms(paste(epc$Date, epc$Time))
epc_sub <- subset(epc, (Datetime >= ymd_hms("2007-02-01 0:0:0") & Datetime <= ymd_hms("2007-02-02 23:59:59")))
png(file="plot1.png", width=480, height = 480)
with(epc_sub, hist(Global_active_power, col="red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)"))
dev.off()