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
20 lines (16 loc) · 725 Bytes
/
plot1.R
File metadata and controls
20 lines (16 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
library(dplyr)
dataset <- read.csv("household_power_consumption.txt", sep = ";")
dataset <- mutate(dataset, Date = as.Date(Date,format="%d/%m/%Y"))
min_date <- as.Date("01/02/2007",format = "%d/%m/%Y")
max_date <- as.Date("02/02/2007",format = "%d/%m/%Y")
dataset<-filter(dataset, Date>=min_date & Date<=max_date)
#Normalize the Active Global Power from factor to numeric
data <- as.numeric(
levels(dataset$Global_active_power))[dataset$Global_active_power]
#Clean the missing values
data <- data[!is.na(data)]
#Save to graphics device, i.e. to a png file
png(file="plot1.png", width = 480, height = 480)
hist(data, main = "Global Active Power",
col = "red", xlab = "Global Active Power (kilowatts)")
dev.off()