-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
22 lines (18 loc) · 679 Bytes
/
plot1.R
File metadata and controls
22 lines (18 loc) · 679 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
## load the data
rm(list = ls())
data <- read.table("household_power_consumption.txt", header = T,
sep = ";", na.strings = "?")
# convert the date variable to Date class
data$Date <- as.Date(data$Date, format = "%d/%m/%Y")
# Subset the data
data <- subset(data, subset = (Date >= "2007-02-01" & Date <= "2007-02-02"))
# Convert dates and times
data$datetime <- strptime(paste(data$Date, data$Time), "%Y-%m-%d %H:%M:%S")
# Plot 1
attach(data)
hist(Global_active_power, main = "Global Active Power",
xlab = "Global Active Power (kilowatts)", col = "Red")
# Save file
dev.copy(png, file = "plot1.png", height = 480, width = 480)
dev.off()
detach(data)