forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
47 lines (35 loc) · 1.57 KB
/
plot3.R
File metadata and controls
47 lines (35 loc) · 1.57 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
46
47
#############################################################################
# Exploratory Data Analysis
# John Hopkins University
# Coursera Course Project
# Author: Anand Rao
# Date: 06 Sep 2014
# Project #1
##############################################################################
require(sqldf)
setwd("~/My Courses/ExploratoryDataAnalysis/Projects")
## Read Data for just the dates 1/2/2007 and 2/2/2007
data <- read.csv.sql( file='household_power_consumption.txt',
sep=";",
sql="select * from file where Date = '1/2/2007' or Date = '2/2/2007'",
header=TRUE)
data$datetime <- as.POSIXct(paste(data$Date, data$Time), format = "%d/%m/%Y %T")
## Open PNG device and create a plot "Plot2" in working directory with
## Width of 480 pixels and height of 480 pixels
png(filename="Plot3.png", width=480, height=480)
## Create a base plot frame with a new Y-axis label and X-axis label
with(data, plot(datetime, Sub_metering_1,
xlab="",
ylab = "Energy sub metering",
type="n"))
## Draw the line for Sub_metering_1 in Black color
with(data, lines(datetime, Sub_metering_1, col="black"))
## Draw the line for Sub_metering_2 in Red color
with(data, lines(datetime, Sub_metering_2, col="red"))
## Draw the line for Sub_metering_3 in Blue color
with(data, lines(datetime, Sub_metering_3, col="blue"))
legend("topright", lty=1,
col=c("black", "red", "blue"),
legend = c("Sub_metering_1","Sub_metering_2", "Sub_metering_3"))
## Close the PNG file device
dev.off()