forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
18 lines (18 loc) · 871 Bytes
/
plot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## Loading the dplyr library
library(dplyr)
## Loading the file
household <- read.csv("household_power_consumption.txt", header=TRUE, sep=";")
## Select only the dates we are interested in
householdSub <- filter(household, Date=="1/2/2007" | Date=="2/2/2007")
## Formatting the dates
householdSub <- mutate(householdSub, DateTime = as.POSIXct(paste(Date, Time), format = '%d/%m/%Y %H:%M:%S'))
## Converting the factors as numerics
householdSub <- mutate(householdSub, Global_active_power = as.numeric(as.character(householdSub$Global_active_power)))
## Create the file to draw in
png(file = "plot2.png", width = 480, height = 480)
## Setting the background color as transparent
par("bg"= "transparent")
## Drawing the plot
with(householdSub, plot(DateTime, Global_active_power, type="l", xlab="", ylab="Global Active Power (kilowatts)"))
## Closing the device
dev.off()