forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plot2.R
14 lines (12 loc) · 797 Bytes
/
Plot2.R
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 = "Plot2.png", width = 480, height = 480)
plot(datasetSub$datetime, datasetSub$Global_active_power, ylab = "Global Active Power (kilowatts)", xlab = "", type = 'l')
dev.off()