-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot1.R
More file actions
26 lines (20 loc) · 1.03 KB
/
plot1.R
File metadata and controls
26 lines (20 loc) · 1.03 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
# Reading the Database
power <- read.table("household_power_consumption.txt", sep =";", header = TRUE,
na.strings = "?", nrows = 72000, colClasses = c("character",
"character","numeric","numeric","numeric","numeric","numeric",
"numeric","numeric"))
# It is Extracted the observations between 1/2/2007 and 2/2/2007, both included
nSelect <- power$Date == "1/2/2007" | power$Date == "2/2/2007"
powerSelect <- power[nSelect,]
# The Date and Time variables are converted to Date/Time classes
fecha <- paste(as.Date(powerSelect[,1],format = "%d/%m/%Y"),powerSelect[,2])
dateTime <- strptime(fecha, "%Y-%m-%d %H:%M:%S")
powerSelect <- cbind(dateTime, powerSelect)
# Open png device; create 'plot1.png'
png(filename = "plot1.png", width = 480, height = 480 )
# Getting the variable
x <- powerSelect$Global_active_power
# Plotting the Grahp
hist(x, col = "red", main = "Global Active Power", xlab = "Global Active Power (Kilowatts)")
# Close the png file device
dev.off()