forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 1
/
plot1.R
18 lines (15 loc) · 768 Bytes
/
plot1.R
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 1
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 = strptime(paste0(data$Date, " ", data$Time), format="%Y-%m-%d %H:%M:%S")
# Plot 1: histogram of global active power
png("./figure/plot1.png", height=480, width=480, bg="transparent")
hist(data[,3], main="Global Active Power", xlab="Global Active Power (kilowatts)", col="red")
dev.off()