Skip to content

Commit 6441cae

Browse files
committed
small edit
1 parent a41658f commit 6441cae

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

plot2.R

+39
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1+
#
2+
#download and unzip file
3+
DownlaodUrl <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
4+
download.file(DownlaodUrl, destfile="data.zip", method="curl")
5+
unzip ("data.zip", exdir = "./")
6+
7+
#read data into rawdata
8+
filename <- "household_power_consumption.txt"
9+
rawdata <- read.table(filename, header=TRUE, na.strings="?", sep=";")
10+
11+
#subset the data required for plotting into plotdata
12+
plotdata <- rawdata[(rawdata$Date=="1/2/2007" | rawdata$Date=="2/2/2007" ), ]
13+
14+
#change the format for date variable to Date from factor
15+
plotdata <- transform(plotdata, Date = as.Date(Date,format = "%d/%m/%Y") )
16+
17+
#add dateTime as paste of date and time with class as POSIXct
18+
plotdata <- transform(plotdata, dateTime = as.POSIXct(paste(plotdata$Date, plotdata$Time)))
19+
20+
#remove the rawdata
21+
rm(rawdata)
22+
23+
#Now create the plot.
24+
25+
## Plot 2
26+
## plot with Global_active_power ~ dateTime variable.
27+
## y-axis label Global Active Power (kilowatts)
28+
## type as l
29+
30+
plot(Global_active_power ~ dateTime, plotdata,
31+
ylab="Global Active Power (kilowatts)", type="l")
32+
33+
#Export the plot into Png
34+
dev.copy(png, file="plot2.png", height=480, width=480)
35+
dev.off()
36+
37+
38+
39+
140

0 commit comments

Comments
 (0)