We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
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'))
t$Date <- as.Date(t$Date, "%d/%m/%Y")
t <- subset(t,Date >= as.Date("2007-2-1") & Date <= as.Date("2007-2-2"))
t <- t[complete.cases(t),]
dateTime <- paste(t$Date, t$Time)
dateTime <- setNames(dateTime, "DateTime")
t <- t[ ,!(names(t) %in% c("Date","Time"))]
t <- cbind(dateTime, t)
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_2dateTime,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(VoltagedateTime, type="l", ylab="Voltage (volt)", xlab="") plot(Sub_metering_1dateTime, type="l", ylab="Global Active Power (kilowatts)", xlab="") lines(Sub_metering_2dateTime,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_powerdateTime, type="l", ylab="Global Rective Power (kilowatts)",xlab="") })
#dev.copy(png, file="plot4.png", height=480, width=480) #dev.off()
The text was updated successfully, but these errors were encountered:
No branches or pull requests
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_1
dateTime, type="l",dateTime,col='Red')ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2
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_power
dateTime, type="l",dateTime, type="l",ylab="Global Active Power (kilowatts)", xlab="")
plot(Voltage
ylab="Voltage (volt)", xlab="")
plot(Sub_metering_1
dateTime, type="l",dateTime,col='Red')ylab="Global Active Power (kilowatts)", xlab="")
lines(Sub_metering_2
lines(Sub_metering_3
dateTime,col='Blue')dateTime, type="l",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
ylab="Global Rective Power (kilowatts)",xlab="")
})
#dev.copy(png, file="plot4.png", height=480, width=480)
#dev.off()
The text was updated successfully, but these errors were encountered: