forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
21 lines (16 loc) · 981 Bytes
/
plot2.R
File metadata and controls
21 lines (16 loc) · 981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# This script was created as part of the Exploratory Data Analysis Course on Coursera
# The goal of this script is to create a plot using the base plotting system.
# Read in data and subset to relevant portion
data <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", stringsAsFactors = FALSE)
dataSub <- subset(data, data$Date == "1/2/2007" | data$Date == "2/2/2007")
# Convert data into usable form (numeric and date objects as relevant)
dataSub$Global_active_power <- as.numeric(dataSub$Global_active_power)
dataSub$DateTime <- paste(dataSub$Date, dataSub$Time, sep = " ")
dataSub$DateTime <- strptime(dataSub$DateTime, "%d/%m/%Y %H:%M:%S")
# Plotting time!
# Open PNG object
png(filename = "plot2.png", width = 480, height = 480)
# Create line plot showing changes in Global Active Power over time
with(dataSub, plot(DateTime,Global_active_power, type = "l", xlab = "", ylab = "Global Active Power (kilowatts)"))
# Close PNG device and save
dev.off()