forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot1.R
24 lines (15 loc) · 759 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
23
24
## reading in dataset
data <- read.csv("./power.txt",header=T, sep=';', na.strings="?",check.names=F, stringsAsFactors=F, comment.char="", quote='\"')
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
## get only Date >= "2007-02-01" & Date <= "2007-02-02" data
subdata <- subset(data, subset=(Date >= "2007-02-01" & Date <= "2007-02-02"))
rm(data)
## Converting dates
datetime <- paste(as.Date(subdata$Date), subdata$Time)
subdata$Datetime <- as.POSIXct(datetime)
## create Plot 1
hist(as.numeric(subdata$Global_active_power), main="Global Active Power",
xlab="Global Active Power", ylab="Frequency", col="Red")
## Saving to .png file
dev.copy(png, file="plot1.png", height=480, width=480)
dev.off()