Course_project - RaulCR/Exploratory-Data-Analysis-week-1 GitHub Wiki
####Plot 1
plot1 <- function() { hist(df$Global_active_power, main = paste("Global Active Power"), col="red", xlab="Global Active Power (kilowatts)") dev.copy(png, file="plot1.png", width=480, height=480) dev.off() cat("Plot1.png has been saved in", getwd()) } plot1()
####Plot 2
plot1 <- function() { plot(df$timestamp,df$Global_active_power, type="l", xlab="", ylab="Global Active Power (kilowatts)") dev.copy(png, file="plot2.png", width=480, height=480) dev.off() cat("plot2.png has been saved in", getwd())Home } plot1()
###Plot3
plot3 <- function() { plot(df$timestamp,df$Sub_metering_1, type="l", xlab="", ylab="Energy sub metering") lines(df$timestamp,df$Sub_metering_2,col="red") lines(df$timestamp,df$Sub_metering_3,col="blue") legend("topright", col=c("black","red","blue"), c("Sub_metering_1 ","Sub_metering_2 ", "Sub_metering_3 "),lty=c(1,1), lwd=c(1,1)) dev.copy(png, file="plot3.png", width=480, height=480) dev.off() cat("plot3.png has been saved in", getwd()) } plot3()
###plot4
plot4 <- function() { par(mfrow=c(2,2))
##PLOT 1
plot(df$timestamp,df$Global_active_power, type="l", xlab="", ylab="Global Active Power")
##PLOT 2
plot(df$timestamp,df$Voltage, type="l", xlab="datetime", ylab="Voltage")
##PLOT 3
plot(df$timestamp,df$Sub_metering_1, type="l", xlab="", ylab="Energy sub metering")
lines(df$timestamp,df$Sub_metering_2,col="red")
lines(df$timestamp,df$Sub_metering_3,col="blue")
legend("topright", col=c("black","red","blue"), c("Sub_metering_1 ","Sub_metering_2 ", "Sub_metering_3 "),lty=c(1,1), bty="n", cex=.5) #bty removes the box, cex shrinks the text, spacing added after labels so it renders correctly
#PLOT 4
plot(df$timestamp,df$Global_reactive_power, type="l", xlab="datetime", ylab="Global_reactive_power")
#OUTPUT
dev.copy(png, file="plot4.png", width=480, height=480)
dev.off()
cat("plot4.png has been saved in", getwd())
} plot4()