forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
22 lines (20 loc) · 997 Bytes
/
plot1.R
File metadata and controls
22 lines (20 loc) · 997 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Normally my functions would be in another file but as per
# assignment I included them
#
load_data <- function(){
mydata<-read.table('data/household_power_consumption.txt', sep=';',nrows=1,
header=TRUE)
data_colnames <- colnames(mydata)
setAs("character","myTime", function(from) as.Date(from, format="%H:%M:%S"))
setAs("character","myDate", function(from) as.Date(from, format="%d/%m/%Y"))
colClasses <- c('myDate', 'myTime', 'numeric', 'numeric', 'numeric',
'numeric', 'numeric', 'numeric', 'numeric')
read.table('data/household_power_consumption.txt', sep=';',nrows=60*24*2,
header=TRUE, colClasses = colClasses,
col.names=data_colnames, skip=36+60*6+60*24*46,
na.strings="?")
}
mydata<-load_data()
png('plot1.png', width=480, height=480, units='px')
hist(mydata$Global_active_power, col='red', xlab='Global Active Power (kilowatts)', main = 'Global Active Power')
dev.off()