Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DUOL #992

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

DUOL #992

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions Duol
Original file line number Diff line number Diff line change
@@ -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
>