forked from rdpeng/ExData_Plotting1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlot1.R
More file actions
24 lines (20 loc) · 959 Bytes
/
Plot1.R
File metadata and controls
24 lines (20 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##download the zip
if (!file.exists("data.zip")) {
fileURL<-"https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2Fhousehold_power_consumption.zip"
download.file(fileURL,destfile="./data.zip")
unzip("data.zip")
}
##read only data from the dates 2007-02-01 and 2007-02-02
data <- read.csv("household_power_consumption.txt",skip=66637,nrows=2880,na.strings = "?",header=F,sep=";")
##load the column headers
names(data) <- names(read.csv("household_power_consumption.txt", nrows=1,sep=";"))
## convert the Date and Time variables to Date/Time
data$Date <- as.Date(data$Date, format="%d/%m/%Y")
data$Time <- paste(data$Date, data$Time, sep=" ")
data$Time <- strptime(data$Time, format="%Y-%m-%d %H:%M:%S")
##define the plot file
png(filename="plot1.png", width=480, height=480)
##plot the grafic
hist(data$Global_active_power, col="red", xlab="Global Active Power (kilowatts)", main="Global Active Power")
##close the file
dev.off()