forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
25 lines (19 loc) · 1.02 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
#Add code here
library(data.table)
datafile <- "household_power_consumption.txt"
# Get the Training Data
pol_data <- read.table(datafile,sep=";",header = TRUE)
library(dplyr)
#x <- filter(pol_data, Date >= "2007-02-01" , Date <= "2007-02-02")
#Convert to POSIX Date and format
pol_data$Date <- as.Date(strptime(pol_data$Date,"%d/%m/%Y"),"%Y-%m-%d" )
#pol_data$Date <- strptime(pol_data$Date,"%d/%m/%Y")
#Format text to be coerced to numerics later
pol_data$Global_active_power <- as.numeric(gsub(",","",pol_data$Global_active_power))
#pol_data$Global_active_power <- as.numeric(pol_data$Global_active_power)
smalldata <- subset(pol_data, Date >= "2007-02-01" & Date <= "2007-02-02")
smalldata$Global_active_power <- as.numeric(smalldata$Global_active_power)
#hist(as.numeric(smalldata$Global_active_power), col = "orange",breaks = 100)
hist(smalldata$Global_active_power, col = "orange",main = "Global Active Power",xlab = "Global Active Power(kilowatts)")
dev.copy(device = png, filename = 'plot1.png', width = 480, height = 480)
dev.off()