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

Plotting Assignment 1 for Exploratory Data Analysis #744

Open
HwayoungNoh opened this issue Dec 13, 2016 · 0 comments
Open

Plotting Assignment 1 for Exploratory Data Analysis #744

HwayoungNoh opened this issue Dec 13, 2016 · 0 comments

Comments

@HwayoungNoh
Copy link

data <- read.csv("~/Exploratory Data Analysis/household_power_consumption.txt", sep=";", na.strings="?",stringsAsFactors = FALSE)
df<- subset(data, data$Date=="1/2/2007"|data$Date=="2/2/2007")
df$Global_active_power <- as.numeric(as.character(df$Global_active_power))
df$Global_reactive_power <- as.numeric(as.character(df$Global_reactive_power))
df$Voltage <- as.numeric(as.character(df$Voltage))
df$Sub_metering_1 <- as.numeric(as.character(df$Sub_metering_1))
df$Sub_metering_2 <- as.numeric(as.character(df$Sub_metering_2))
df$Sub_metering_3 <- as.numeric(as.character(df$Sub_metering_3))
df$Datetime <-paste(df$Date, df$Time)

#Plot1
plot1

png("plot1.png", width=480, height=480)
hist(df$Global_active_power, col="red", main="Global Active Power",xlab="Global Active Power (kilowatts)")
dev.off()

#Plot2
plot2

png("plot2.png", width=480, height=480)
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Global_active_power, type="l", xlab="",ylab="Global Active Power(Kilowatts)" )
dev.off()

#Plot3
plot3

png("plot3.png", width=480, height=480)
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_2, type = "l", col="red")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_3, type = "l", col="blue")
legend("topright",lty=1, col=c("black", "red", "blue"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))

#Plot4
plot4

png("plot4.png", width=480, height=480)
par(mfcol = c(2,2))
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Global_active_power, type="l", xlab="",ylab="Global Active Power(Kilowatts)" )
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_1, type = "l", xlab = "", ylab = "Energy sub metering")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_2, type = "l", col="red")
lines(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Sub_metering_3, type = "l", col="blue")
legend("topright",lty=1, col=c("black", "red", "blue"), legend=c("Sub_metering_1", "Sub_metering_2", "Sub_metering_3"))
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$Voltage, type = "l", xlab = "datetime", ylab = "Voltage")
plot(strptime(df$Datetime, "%d/%m/%Y %H:%M:%S"), df$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