forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
41 lines (30 loc) · 1.32 KB
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
###--------------------------------------------------------------
### plot1.R:
### Creates a histogram of Household Global Active Power
###
### Date By Notes
### 2014-05-07 saoconnell Initial development
###--------------------------------------------------------------
## CLEANUP THE WORK SPACE
rm(list=ls())
### SET THE WORKING DIRECTORY
setwd("~/Documents/workspace/coursera/Data_Science/Exploratory_Data_Analysis/assignment_one/ExData_Plotting1")
### READ IN DATA
in_data <- read.csv("household_power_consumption.txt", sep=';', header=TRUE, stringsAsFactors=FALSE)
## CONVERT COLUMNS TO NUMERIC (WARNING IS '?' ARE COERCED TO NA)
in_data$Global_active_power <- as.numeric(in_data$Global_active_power)
in_data$Sub_metering_1 <- as.numeric(in_data$Sub_metering_1)
in_data$Sub_metering_2 <- as.numeric(in_data$Sub_metering_2)
## CREATE A POSIX DATE FOR SUBSETTING
in_data$POSIX <- as.POSIXct(strptime(paste(in_data$Date, in_data$Time), format="%d/%m/%Y %H:%M:%S"))
### SUBSET DATA
plot_data <- subset(in_data, POSIX >= as.POSIXct("2007-02-01") & POSIX < as.POSIXct("2007-02-03") )
summary(plot_data)
### PLOT DATA
png("plot1.png", width = 480, height = 480)
hist(plot_data$Global_active_power,
col='red',
main="Global Active Power",
xlab="Global Active Power(kilowatts)"
)
dev.off()