forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
26 lines (23 loc) · 1.26 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
#load the power dataset
setwd("C:/Users/washbuan.ENGINEERING/Documents/R")
power <- read.csv2("household_power_consumption.txt")
#wrangle the date
febPower <- subset(power, Date == "1/2/2007" | Date == "2/2/2007")
febPower$Date <- as.character(febPower$Date)
febPower$Time <- as.character(febPower$Time)
febPower$Event <- as.POSIXct(paste(febPower$Date, febPower$Time, sep=" "), format = "%d/%m/%Y %H:%M:%S")
febPower$Global_active_power <- as.numeric(as.character(febPower$Global_active_power))
febPower$Global_reactive_power <- as.numeric(as.character(febPower$Global_reactive_power))
febPower$Voltage <- as.numeric(as.character(febPower$Voltage))
febPower$Global_intensity <- as.numeric(as.character(febPower$Global_intensity))
febPower$Sub_metering_1 <- as.numeric(as.character(febPower$Sub_metering_1))
febPower$Sub_metering_2 <- as.numeric(as.character(febPower$Sub_metering_2))
febPower$Sub_metering_3 <- as.numeric(as.character(febPower$Sub_metering_3))
str(febPower) #check data is in correct formats
#histogram of Global Active Power
activePowerHist<-function(){
hist(febPower$Global_active_power, col = 'red', xlab = 'Global Active Power (kilowatts)', ylab = 'Frequency', main = 'Global Active Power')
}
png('plot1.png')
activePowerHist()
dev.off()