forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot1.R
22 lines (16 loc) · 947 Bytes
/
plot1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# set the working directory
#setwd("~/Coursea/Explore")
#set the intitial classes for the imported columns
hdr.classes <- c("character","character","numeric","numeric","numeric","numeric","numeric","numeric","numeric")
# load the household power data into memory
data <- read.table("household_power_consumption.txt", header = TRUE, colClasses = hdr.classes,sep = ";", stringsAsFactors = FALSE, na.strings = "?")
# remove all but the first 2 days in February
library(dplyr)
data <- filter(data, Date %in% c("1/2/2007","2/2/2007"))
# convert date and time to Date/Time classes
data <- transform(data, Date = as.Date(Date, format='%d/%m/%Y'), Time = strptime(paste(Date,Time), format='%d/%m/%Y %H:%M:%S'))
# open a png graphical device
png(file="plot1.png", width = 480, height=480)
#par(mar= c(5,4,4,2) + 0.1)
with(data, hist(Global_active_power, col = "Red", main = "Global Active Power", xlab ="Global Active Power (kilowatts)"))
dev.off()