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

Electric-power-plots-Alba #923

Open
Albita26 opened this issue Jun 16, 2020 · 0 comments
Open

Electric-power-plots-Alba #923

Albita26 opened this issue Jun 16, 2020 · 0 comments

Comments

@Albita26
Copy link

knitr::opts_chunk$set(echo = TRUE, results = "asis")

t <- read.table("household_power_consumption.txt", header=TRUE, sep=";", na.strings = "?", colClasses = c('character','character','numeric','numeric','numeric','numeric','numeric','numeric','numeric'))

Formato

t$Date <- as.Date(t$Date, "%d/%m/%Y")

Filter data set from Feb. 1, 2007 to Feb. 2, 2007

t <- subset(t,Date >= as.Date("2007-2-1") & Date <= as.Date("2007-2-2"))

Remove incomplete observation

t <- t[complete.cases(t),]

Combine Date and Time column (combinar datos y columnas)

dateTime <- paste(t$Date, t$Time)

Name the vector/Dar nombre al vector

dateTime <- setNames(dateTime, "DateTime")

Remove Date and Time column/Eimino columna fecha y tiempo

t <- t[ ,!(names(t) %in% c("Date","Time"))]

Add DateTime columna

t <- cbind(dateTime, t)

Format dateTime columna/formateo

t$dateTime <- as.POSIXct(dateTime)

##Crear histograma PLOT 1
hist(t$Global_active_power, main="Global Active Power", xlab = "Global Active Power (kilowatts)", col="red")

#dev.copy(png,"plot1.png", width=480, height=480)
#dev.off()

##PLOT 2
plot(t$Global_active_power~t$dateTime, type="l", ylab="Global Active Power (kilowatts)", xlab="")

#dev.copy(png,"plot2.png", width=480, height=480)
#dev.off()

##PLOT 3
with(t, {
plot(Sub_metering_1dateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2
dateTime,col='Red')
lines(Sub_metering_3~dateTime,col='Blue')
})
legend("topright", col=c("black", "red", "blue"), lwd=c(1,1,1),
c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))

#dev.copy(png, file="plot3.png", height=480, width=480)
#dev.off()

##PLOT 4
par(mfrow=c(2,2), mar=c(4,4,2,1), oma=c(0,0,2,0))
with(t, {
plot(Global_active_powerdateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
plot(Voltage
dateTime, type="l",
ylab="Voltage (volt)", xlab="")
plot(Sub_metering_1dateTime, type="l",
ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2
dateTime,col='Red')
lines(Sub_metering_3dateTime,col='Blue')
legend("topright", col=c("black", "red", "blue"), lty=1, lwd=2, bty="n",
legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(Global_reactive_power
dateTime, type="l",
ylab="Global Rective Power (kilowatts)",xlab="")
})

#dev.copy(png, file="plot4.png", height=480, width=480)
#dev.off()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant