forked from rdpeng/ProgrammingAssignment2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
22 lines (17 loc) · 791 Bytes
/
plot1.R
File metadata and controls
22 lines (17 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Date1 <- strptime("01/02/2007","%d/%m/%Y") # first date in data to analyse
Date2 <- strptime("02/02/2007","%d/%m/%Y") # second date in data to analyse
## Read whole data
data <- read.csv2("household_power_consumption.txt",
stringsAsFactors = FALSE,
na.strings = "?")
## use only data for specified dates
data <- data[strptime(data$Date, "%d/%m/%Y") == Date1 |
strptime(data$Date, "%d/%m/%Y") == Date2,]
png(file="plot1.png") ## open png device
hist(as.double(data$Global_active_power), ## convert text to double
main="Global Active Power", ## main heading
xlab = "Global Active Power (kilowatts)", ## x-axis text
ylab = "Frequency", ## y-axis text
border = NULL, ## no border lines
col="red") ## color of bars
dev.off() ## close device