forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot2.R
21 lines (21 loc) · 1.1 KB
/
plot2.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# In order to use this code, download the
# Electric Power Consumption file from here:
# https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip
# Place the file in the Documents Folder
#Also, it is assumed that the Github repo "Ex_data Plotting 1"
#is nested in a folder named "GitHub" located in the Documents Folder.
#Also, install the package "lubridate".
setwd("~/Documents")
HPC<-read.table("household_power_consumption.txt",sep=";",header=TRUE,
comment.char = "",colClasses=
c("character","character","numeric","numeric","numeric"
,"numeric","numeric","numeric","numeric"),na.strings="?")
HPC$datetime<-strptime(paste(HPC$Date,HPC$Time),format="%d/%m/%Y %H:%M:%S")
library(lubridate)
HPCsub<-subset(HPC,month(datetime)==2&(day(datetime)==1|day(datetime)==2)&
year(datetime)==2007)
plot(HPCsub$datetime,HPCsub$Global_active_power,type="l",
ylab="Global Active Power (kilowatts)",xlab="",bg ="transparent" )
setwd("~/Documents/GitHub/ExData_Plotting1")
dev.copy(png, file = "plot2.png")
dev.off()