diff --git a/Duol b/Duol new file mode 100644 index 00000000000..df18264711b --- /dev/null +++ b/Duol @@ -0,0 +1,85 @@ +powerConsum <- read.csv("household_power_consumption.txt", sep = ";", stringsAsFactors = FALSE) +> +> +> powerConsum <- read.csv("household_power_consumption.txt", sep = ";", stringsAsFactors = FALSE) +> +> powerConsum$Date <- as.Date(powerConsum$Date, format = "%d/%m/%Y") +> +> powerConsum$DateTime <- strptime(paste(powerConsum$Date,powerConsum$Time), ++ format = "%Y-%m-%d %H:%M:%S") +> powerConsum <- powerConsum[powerConsum$Date >= "2007-2-1" & powerConsum$Date <= "2007-2-2",] +> +> powerConsum[,3] <- as.numeric(powerConsum[,3]) +> powerConsum[,4] <- as.numeric(powerConsum[,4]) +> powerConsum[,5] <- as.numeric(powerConsum[,5]) +> powerConsum[,6] <- as.numeric(powerConsum[,6]) +> powerConsum[,7] <- as.numeric(powerConsum[,7]) +> powerConsum[,8] <- as.numeric(powerConsum[,8]) +> with(powerConsum, hist(Global_active_power, xlab = "Global Active Power (kilowatts)", ++ col = "red", main = "Global Active Power")) +> dev.copy(device = png, width = 480, height = 480, file = "Plot1.png") +png + 4 +> +> with(powerConsum, plot(DateTime, Global_active_power, type = "l", xlab = "", ++ ylab = "Global Active Power (kilowatts)", xaxt = "n")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> dev.copy(device = png, width = 480, height = 480, file = "Plot2.png") +png + 5 +> with(powerConsum, plot(DateTime, Sub_metering_1, type = "n", xaxt = "n", ++ xlab = "", ylab = "Energy sub metering")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> with(powerConsum, lines(DateTime, Sub_metering_1)) +> with(powerConsum, lines(DateTime, Sub_metering_2, col = "red")) +> +> with(powerConsum, lines(DateTime, Sub_metering_3, col = "blue")) +> legend("topright",lty = 1, col=c("black","red","blue"), ++ legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3")) +> dev.copy(device = png, width = 480, height = 480, file = "Plot3.png") +png + 6 +> +> par(mfrow = c(2,2)) +> +> with(powerConsum, plot(DateTime, Global_active_power, type = "l", xlab = "", ++ ylab = "Global Active Power", xaxt = "n")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> +> with(powerConsum, plot(DateTime, Voltage, type = "l", xlab = "datetime", ylab = "Voltage", ++ xaxt = "n")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> +> with(powerConsum, plot(DateTime, Sub_metering_1, type = "n", xaxt = "n", ++ xlab = "", ylab = "Energy sub metering")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> with(powerConsum, lines(DateTime, Sub_metering_1)) +> with(powerConsum, lines(DateTime, Sub_metering_2, col = "red")) +> with(powerConsum, lines(DateTime, Sub_metering_3, col = "blue")) +> legend("topright",lty = 1, col=c("black","red","blue"), ++ legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3")) +> with(powerConsum, plot(DateTime, Global_reactive_power, type= "l", xlab = "datetime", ++ ylab = "Global_reactive_power", xaxt = "n")) +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +Error in axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), as.numeric(powerConsum$DateTime[1441]), : + 'at' and 'labels' lengths differ, 4 != 3 +> axis(side = 1, at = c(as.numeric(powerConsum$DateTime[1]), ++ as.numeric(powerConsum$DateTime[1441]), ++ as.numeric(powerConsum$DateTime[2880])),labels = c("Thu","Fri","Sat")) +> dev.copy(device = png, width = 480, height = 480, file = "Plot4.png") +png + 7 +>