forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
41 lines (36 loc) · 1.34 KB
/
plot1.R
File metadata and controls
41 lines (36 loc) · 1.34 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
rawDataFileName <- "../household_power_consumption.txt"
# Read the data from the file.
# For now keep the date and time as a character strings.
d <- read.table(rawDataFileName,
header = TRUE,
sep = ";",
na.strings = "?",
colClasses = c("character",
"character",
"numeric",
"numeric",
"numeric",
"numeric",
"numeric",
"numeric",
"numeric"
),
comment.char = ""
)
# Keep only the needed dates.
# The dates appear to be in the D/M/YYYY format,
# without leading zeros.
d <- subset(d, Date %in% c("1/2/2007", "2/2/2007"))
# Convert the Date and Time character strings to a timestamp.
d$Timestamp <- as.POSIXct(paste(d$Date, d$Time, sep = " "),
format = "%d/%m/%Y %H:%M:%S")
# Drop the Date and Time character strings.
d <- d[, ! names(d) %in% c("Date", "Time")]
# Draw a histogram of the Global_active_power.
png("plot1.png")
hist(d$Global_active_power,
col = "red",
main = "Global Active Power",
xlab = "Global Active Power (kilowatts)"
)
dev.off()