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
14 lines (12 loc) · 796 Bytes
/
Plot1.R
File metadata and controls
14 lines (12 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# download file
temp <- tempfile()
download.file("https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip",temp)
# Read data, convert into date format and extract relevant data
dataset <- read.table(unz(temp, "household_power_consumption.txt"), sep = ";", na.strings = "?", header = TRUE)
dataset$datetime <- strptime(paste(dataset$Date, dataset$Time), format = "%d/%m/%Y %H:%M:%S")
dataset$Date <- as.Date(dataset$Date, format = "%d/%m/%Y")
datasetSub <- subset(dataset, dataset$Date >= as.Date("2007-02-01") & dataset$Date <= as.Date("2007-02-02"))
# Plot and label histogram
png(filename = "Plot1.png", width = 480, height = 480)
hist(datasetSub$Global_active_power, col = "red", main = "Global Active Power", xlab = "Global Active Power (kilowatts)")
dev.off()