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
22 lines (16 loc) · 1.02 KB
/
plot2.R
File metadata and controls
22 lines (16 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
setwd("C:\\Users\\EriksLaptop\\Documents\\DataScientistClasses\\ExploreData\\proj1")
library(sqldf)
#####################Get Data for Analysis##########################
data1 <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(data1,"power1.zip",mode="wb") #Download from internet
unzip("power1.zip") #Unzip file into working directory set above
elect1 <- read.csv.sql("household_power_consumption.txt",
sql = 'select * from file where Date in ("1/2/2007","2/2/2007")',
header=TRUE,sep=";") #Read only dates required using SQL
#Convert date and time fields into a R data/time variable
elect1$datetm <-strptime(paste(elect1$Date, elect1$Time, sep=" "),"%d/%m/%Y %H:%M:%S")
elect1 <- elect1[,-c(1,2)] #Remove unneeded Date and Time fields
#####################Make Plot 2###########################
dev.copy(png,'plot2.png')
plot(elect1$datetm,elect1$Global_active_power,type="l",xlab="",ylab="Global Active Power (kilowatts)")
dev.off()