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 (18 loc) · 1.04 KB
/
Copy pathplot2.R
File metadata and controls
22 lines (18 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#it is assumed that the data file is in the working directory named "household_power_consumption.txt
data<-read.table("household_power_consumption.txt",header=TRUE,sep=";",na.strings="?", colClasses=c("character","character", rep("numeric",7)))
#subset
data<- data[(data$Date == "1/2/2007")|(data$Date == "2/2/2007"),]
#crate one Date Time variable
x <- paste(data$Date, data$Time)
data$DT <-strptime(x, "%d/%m/%Y %H:%M:%S")
#create plot in png file
#xaxt="n" is there because of the local language settings. Since I'm using non-english
#system, the days labels are not in english, therefore First I created plot without the
#x-label and then I manually added the labels.
#The command:
#plot(data$DT, data$Global_active_power, type = "l", ylab = "Global Active Power (kilowatts)", xlab="")
#will create plot using the defalut langugae settings
png("plot2.png",width=480, height=480)
plot(data$Global_active_power, type = "l", ylab = "Global Active Power (kilowatts)", xlab="", xaxt="n")
axis(1, at=c(1, 1440, 2880), labels=c("Thu", "Fri", "Sat"))
dev.off()