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 (11 loc) · 983 Bytes
/
plot2.R
File metadata and controls
22 lines (11 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
## Load the data, here we assume that the document "household_power_consumption.txt" is unzip and in the working directory
data <- read.table("household_power_consumption.txt",sep=";",header=TRUE,na.strings="?") ## Loading the data
data <- subset(data,data$Date=="1/2/2007" | data$Date=="2/2/2007") ## subsetting the relevant dates
data <- na.omit(data) ## Removing NA's
data$Time <- strptime(paste(data$Date,data$Time),format = "%d/%m/%Y %H:%M:%S", tz = "") ## Concatenate Date and Time Collumn in a new collumn, and transforming both to strings
data$Date <- as.Date(data$Date,"%d/%m/%Y") ## Transform created collumn to a date format
## Make the plot
png("plot2.png", width=480, height=480, units="px", bg = "transparent") ## Calling the Graphics devices with the png requirements, and transparent background
plot(data$Time,data$Global_active_power,
type="l",xlab="",ylab="Global Active Power (kilowatts)") ##Plotting the line graph
dev.off() ## Closing png device