forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot2.R
More file actions
45 lines (36 loc) · 1.26 KB
/
plot2.R
File metadata and controls
45 lines (36 loc) · 1.26 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
41
42
43
44
45
# Plot 2
## Load packages
library(dplyr)
library(ggplot2)
library(png)
## Estimate memory needed
# memory required = no. of column * no. of rows * 8 bytes/numeric
# memory = 9 * 2075259 * 8 = 149,418,648
## read in data
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(url, destfile = "household_power_consumption.zip")
unzip("household_power_consumption.zip")
epc <- read.table("household_power_consumption.txt", header = TRUE, sep = ";", stringsAsFactors = FALSE)
object.size(epc)
#actual memory is 150,050,248 bytes
# Format Date and Time columns
epc$Date <- as.Date(epc$Date, format = "%d/%m/%Y")
epc$Time <- format(epc$Time, format = "%H:%M:%S")
str(epc)
summary(epc)
#Filter tp only use data from the dates 2007-02-01 and 2007-02-02.
epc <- epc %>%
filter(Date >= "2007-02-01" & Date<= "2007-02-02")
summary(epc)
str(epc)
#Convert columns to numeric
epc[3:8] <- lapply(epc[3:8], FUN = function(y){as.numeric(y)})
str(epc)
summary(epc)
#Plot 2
png("plot2.png")
plot(epc$Global_active_power, type = "l", main = "", ylab = "Global Active Power (kilowatts)", xlab = "", axes=FALSE)
axis(1, at = c(0, 1500, 2900), labels = c("Thu", "Fri", "Sat"))
axis(2, at = c(0, 2, 4, 6))
box(lty = 1, col = 'black')
dev.off()