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

Project 1 #785

Open
chloeliu123 opened this issue May 8, 2017 · 0 comments
Open

Project 1 #785

chloeliu123 opened this issue May 8, 2017 · 0 comments

Comments

@chloeliu123
Copy link

chloeliu123 commented May 8, 2017

plot1

consumption<-read.table("household_power_consumption.txt",sep=";",header=TRUE,stringsAsFactors=F, na.strings="?")
consumption$Date<-as.Date(consumption$Date,format='%d/%m/%Y')
head(consumption$Date)
consumption1<-subset(consumption,Date%in%as.Date(c("2007-02-01","2007-02-02")))
consumption1$DateTime=as.POSIXct(paste(consumption1$Date,consumption1$Time))
consumption1$Global_active_power<-as.numeric(consumption1$Global_active_power)
png("plot1.png", width=480, height=480)
hist(consumption1$Global_active_power,xlab="Global Active Power(kilowatts)",ylab="Frequency",main="Global Active Power",col="red")
dev.off()

plot2

consumption<-read.table("household_power_consumption.txt",sep=";",header=TRUE,stringsAsFactors=F, na.strings="?")
consumption$Date<-as.Date(consumption$Date,format='%d/%m/%Y')
head(consumption$Date)
consumption1<-subset(consumption,Date%in%as.Date(c("2007-02-01","2007-02-02")))
consumption1$DateTime=as.POSIXct(paste(consumption1$Date,consumption1$Time))
consumption1$Global_active_power<-as.numeric(consumption1$Global_active_power)
DateTime<-consumption1$DateTime
png("plot2.png", width=480, height=480)
plot(x=DateTime,y=consumption1$Global_active_power,type="l",xlab="",ylab="Global Active Power (kilowatts)")
dev.off()

plot3

consumption<-read.table("household_power_consumption.txt",sep=";",header=TRUE,stringsAsFactors=F, na.strings="?")
consumption$Date<-as.Date(consumption$Date,format='%d/%m/%Y')
head(consumption$Date)
consumption1<-subset(consumption,Date%in%as.Date(c("2007-02-01","2007-02-02")))
consumption1$DateTime=as.POSIXct(paste(consumption1$Date,consumption1$Time))
consumption1$Global_active_power<-as.numeric(consumption1$Global_active_power)
DateTime<-consumption1$DateTime
plot(x=DateTime,y=consumption1$Sub_metering_1,xlab="",type="l",ylab="Energy sub metering")
lines(x=DateTime,y=consumption1$Sub_metering_2,col="red")
lines(x=DateTime,y=consumption1$Sub_metering_3,col="blue")
legend("topright", col=c("black", "red", "blue"), lty=1, lwd=2,legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))

plot4

png("plot4.png", width=480, height=480)
par(mfrow=c(2,2))
plot(x=DateTime,y=consumption1$Global_active_power,type="l",xlab="",ylab="Global Active Power (kilowatts)")
plot(x=DateTime,y=consumption1$Voltage,type="l",xlab="datetime",ylab="Voltage")
plot(x=DateTime,y=consumption1$Sub_metering_1,xlab="",type="l",ylab="Energy sub metering")
lines(x=DateTime,y=consumption1$Sub_metering_2,col="red")
lines(x=DateTime,y=consumption1$Sub_metering_3,col="blue")
legend("topright", col=c("black", "red", "blue"), lty=1, lwd=2,legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(x=DateTime,y=consumption1$Global_reactive_power,type="l",xlab="datetime",ylab="Global_reactive_power")
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