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

Homework 1 #736

Open
LuisPerezAlvarado opened this issue Nov 11, 2016 · 0 comments
Open

Homework 1 #736

LuisPerezAlvarado opened this issue Nov 11, 2016 · 0 comments

Comments

@LuisPerezAlvarado
Copy link

plot1

#Plot 1 Global Active Power
library(data.table)
plot1<-fread("household_power_consumption.txt")
subset<-plot1[plot1$Date %in% c("1/2/2007","2/2/2007"),]
png("Plot1.png", width=480, height=480)
hist(as.numeric(subset$Global_active_power), col="red", main="Global Active Power", xlab="Global Active Power (Kilowatts)")
dev.off();

plot2

#Plot 2
library(data.table)
plot2<-fread("household_power_consumption.txt")
mydata<-plot2[plot2$Date %in% c("1/2/2007","2/2/2007"),]
datetime<-strptime(paste(mydata$Date,mydata$Time, sep=" "),"%d/%m/%Y %H:%M:%S")
png("plot2", width=480, height=480)
plot(datetime, mydata$Global_active_power,xlab="",ylab="Global Active Power (Killowatts)",type="l")
dev.off()

plot3

#Plot 3
library(data.table)
plot3<-fread("household_power_consumption.txt")
subsetdata<-plot3[plot3$Date %in% c("1/2/2007","2/2/2007"),]
DateTime<-strptime(paste(subsetdata$Date, subsetdata$Time, sep=" "),"%d/%m/%Y %H:%M:$S")
png("Plot3",width=480,height=480)
plot(DateTime,subsetdata$Sub_metering_1,xlab="",ylab="Energy sub metering",type="l")
lines(DateTime,subsetdata$Sub_metering_2,col="red")
lines(DateTime,subsetdata$Sub_metering_3,col="blue")
legend("topright",col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
dev.off()

plot4

#Plot 4
library(data.table)
plot4<-fread("household_power_consumption.txt")
subsetdata<-plot4[plot4$Date %in% c("1/2/2007","2/2/2007"),]
DateTime<-strptime(paste(subsetdata$Date, subsetdata$Time, sep=" "),"%d/%m/%Y %H:%M:%S")
png("plot4.png",width=480,height=480)
par(mfrow=c(2,2))
plot(DateTime,subsetdata$Global_active_power,xlab="",ylab="Global Active Power",type="l")
plot(DateTime,subsetdata$Voltage,xlab="DateTime",ylab="Voltage",type="l")
plot(DateTime,subsetdata$Sub_metering_1,xlab="",ylab="Energy sub metering",type="l")
lines(DateTime,subsetdata$Sub_metering_2,col="red")
lines(DateTime,subsetdata$Sub_metering_3,col="blue")
legend("topright",col=c("black","red","blue"),legend=c("Sub_metering_1","Sub_metering_2","Sub_metering_3"))
plot(DateTime,subsetdata$Global_reactive_power,xlab="",ylab="Global_reactive_power",type="l")
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