forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot2.R
More file actions
18 lines (15 loc) · 798 Bytes
/
Copy pathplot2.R
File metadata and controls
18 lines (15 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Exploratory data analysis
# Course project 1
# Plot 2
setwd("~/Copy/Michael/training/Coursera_datascience/ExplDataAnal/Project1/ExData_Plotting1")
# Read data
data = read.csv("../household_power_consumption.txt", sep=";", na.strings="?", skip=66637, nrows=2879, header=F)
# Add column names
colnames(data) = read.csv("../household_power_consumption.txt", sep=";", nrows=1, header=F, stringsAsFactors=F)
# Tidy data
data$Date = as.Date(data$Date, format="%d/%m/%Y")
data$Time = as.POSIXct(strptime(paste0(data$Date, " ", data$Time), format="%Y-%m-%d %H:%M:%S"))
# Plot 2: histogram of global active power
png("./figure/plot2.png", height=480, width=480, bg="transparent")
plot(Global_active_power ~ Time, data=data, main="", xlab="", ylab="Global Active Power (kilowatts)", type="l")
dev.off()