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
18 lines (14 loc) · 801 Bytes
/
plot1.R
File metadata and controls
18 lines (14 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
colclasses = c("character", "character", rep("numeric",7))
data <- read.csv("household_power_consumption.txt", colClasses = colclasses, na.strings=c("?"), sep=";")
# Paste the date and time fields onto each other and into a new field called DateTime
data <- within(data, DateTime <- paste(Date, Time, sep=" "))
# Remove exces data to save memory
data$Date = NULL
data$Time = NULL
# Convert DateTime (character) to a real Date
data$DateTime = as.POSIXct(strptime(data$DateTime, format = "%d/%m/%Y %H:%M:%S"))
data = subset(data, DateTime >= as.POSIXct("2007-02-01") & DateTime < as.POSIXct("2007-02-03"))
# Plot 1
png(filename="plot1.png", width = 480, height = 480)
hist(as.numeric(data$Global_active_power), xlab="Global Active Power (kilowatts)", col="red", main="Global Active Power")
dev.off()