<file_sep>#load large file
data <- read.table(  "household_power_consumption.txt",  sep=";", header=TRUE, na.strings='?',
                     colClasses=c(rep('character', 2), 
                                  rep('numeric', 7)))
#filter the target date
data<-data[data["Date"]=="1/2/2007"|data["Date"]=="2/2/2007",]

#convert date DateTime
data$Date <- as.Date(data$Date , "%d/%m/%Y")
data$DateTime <- paste(data$Date, data$Time, sep=" ")
data$DateTime <- strptime(data$DateTime, "%Y-%m-%d %H:%M:%S")


png("plot4.png", width = 480, height = 480)
par(mfrow = c(2, 2))
with(data, {
  plot(DateTime, Global_active_power, type = "l", xlab = "", ylab = "Global Active Power")
  
  plot(DateTime, Voltage, xlab = "DateTime", type = "l", ylab = "Voltage")
  
  ylimits = range(c(data$Sub_metering_1, data$Sub_metering_2, data$Sub_metering_3))
  plot(DateTime, Sub_metering_1, xlab = "", ylab = "Energy sub metering", type = "l", ylim = ylimits, col = "black")
  
  par(new = TRUE)
  plot(DateTime, Sub_metering_2, xlab = "", axes = FALSE, ylab = "", type = "l", ylim = ylimits, col = "red")
  par(new = TRUE)
  plot(DateTime, Sub_metering_3, xlab = "", axes = FALSE, ylab = "", type = "l", ylim = ylimits, col = "blue")
  legend("topright",
         legend = c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"),
         bg = "transparent",
         bty = "n",
         lty = c(1,1,1),
         col = c("black", "red", "blue")
  )
  
  plot(DateTime, Global_reactive_power, type = "l", xlab = "DateTime", ylab = "Global_reactive_power")
  
})
dev.off
<file_sep>#load large file
data <- read.table(  "household_power_consumption.txt",  sep=";", header=TRUE, na.strings='?',
                     colClasses=c(rep('character', 2), 
                                  rep('numeric', 7)))
#filter the target date
data<-data[data["Date"]=="1/2/2007"|data["Date"]=="2/2/2007",]

#convert date DateTime
data$Date <- as.Date(data$Date , "%d/%m/%Y")
data$DateTime <- paste(data$Date, data$Time, sep=" ")
data$DateTime <- strptime(data$DateTime, "%Y-%m-%d %H:%M:%S")

png("plot1.png")
hist(data$Global_active_power, main = "Global Active power", col = "red", xlab = "Global Active Power (kilowatts)", )
dev.off()
<file_sep>#load large file
data <- read.table(  "household_power_consumption.txt",  sep=";", header=TRUE, na.strings='?',
                     colClasses=c(rep('character', 2), 
                                  rep('numeric', 7)))
#filter the target date
data<-data[data["Date"]=="1/2/2007"|data["Date"]=="2/2/2007",]

#convert date DateTime
data$Date <- as.Date(data$Date , "%d/%m/%Y")
data$DateTime <- paste(data$Date, data$Time, sep=" ")
data$DateTime <- strptime(data$DateTime, "%Y-%m-%d %H:%M:%S")



png("plot3.png")
plot(x=(data$DateTime),y=data$Sub_metering_1,type="l",ylab="Energy sub metering",xlab="")
lines(x=(data$DateTime),y=data$Sub_metering_2,col="red")
lines(x=(data$DateTime),y=data$Sub_metering_3,col="blue")
legend("topright",c("Sub_metering_1","Sub_metering_2","Sub_metering_3"),bty="l",col=c("black","red","blue"),lwd=2,cex=0.7)
dev.off()
