You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#Plot1
png("plot1.png", width=480, height=480)
hist(df$Global_active_power, col="red", main="Global Active Power",xlab="Global Active Power (kilowatts)")
dev.off()
data <- read.csv("D:\User\Courses\R Programming\Week1//household_power_consumption.txt", sep=";", na.strings="?",stringsAsFactors = FALSE)
df<- subset(data, data$Date=="1/2/2007"|data$Date=="2/2/2007")
df$Global_active_power <- as.numeric(as.character(df$Global_active_power))
df$Global_reactive_power <- as.numeric(as.character(df$Global_reactive_power))
df$Voltage <- as.numeric(as.character(df$Voltage))
df$Sub_metering_1 <- as.numeric(as.character(df$Sub_metering_1))
df$Sub_metering_2 <- as.numeric(as.character(df$Sub_metering_2))
df$Sub_metering_3 <- as.numeric(as.character(df$Sub_metering_3))
df$Datetime <-paste(df$Date, df$Time)
#Plot1

png("plot1.png", width=480, height=480)
hist(df$Global_active_power, col="red", main="Global Active Power",xlab="Global Active Power (kilowatts)")
dev.off()
#Plot2

png("plot2.png", width=480, height=480)
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Global_active_power, type="l", xlab="",ylab="Global Active Power(Kilowatts)" )
dev.off()
#Plot3

png("plot3.png", width=480, height=480)
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_2, type = "l", col="red")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_3, type = "l", col="blue")
legend("topright",lty=1, col=c("black", "red", "blue"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
#Plot4

png("plot4.png", width=480, height=480)
par(mfcol = c(2,2))
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Global_active_power, type="l", xlab="",ylab="Global Active Power(Kilowatts)" )
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_2, type = "l", col="red")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_3, type = "l", col="blue")
legend("topright",lty=1, col=c("black", "red", "blue"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Voltage, type = "l", xlab = "datetime", ylab = "Voltage")
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Global_reactive_power, type = "l", xlab = "datetime", ylab = "Global_reactive_power")
dev.off()
The text was updated successfully, but these errors were encountered: