Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions plot1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE)

times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S")

date=data.frame(as.Date(dat$Date, "%d/%m/%Y"))

dat$Date=as.Date(dat$Date, "%d/%m/%Y")

dat$newtimes=times

dat2<-dat[dat$Date>= "2007-02-01",]

dat3<-dat2[dat2$Date <= "2007-02-02",]

hist(as.numeric(dat3$Global_active_power), col = "red", xlab = "Global Active Power (kilowatts)", main = "Global Active Power")
dev.copy(png,'plot1.png')
dev.off()
Binary file added plot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions plot2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE)

times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S")

date=data.frame(as.Date(dat$Date, "%d/%m/%Y"))

dat$Date=as.Date(dat$Date, "%d/%m/%Y")

dat$newtimes=times

dat2<-dat[dat$Date>= "2007-02-01",]

dat3<-dat2[dat2$Date <= "2007-02-02",]

plot(dat3$newtimes,dat3$Global_active_power, type="l", ylab = "Global Active Power (kilowatts)")
dev.copy(png,'plot2.png')
dev.off()
Binary file added plot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 20 additions & 0 deletions plot3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE)

times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S")

date=data.frame(as.Date(dat$Date, "%d/%m/%Y"))

dat$Date=as.Date(dat$Date, "%d/%m/%Y")

dat$newtimes=times

dat2<-dat[dat$Date>= "2007-02-01",]

dat3<-dat2[dat2$Date <= "2007-02-02",]

plot(dat3$newtimes,dat3$Sub_metering_1, type="l", ylab = "Energy sub metering")
points(dat3$newtimes,dat3$Sub_metering_2, type = "l", col = "red")
points(dat3$newtimes,dat3$Sub_metering_3, type="l", col = "blue")
legend(x ="topright", legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), col = c("black", "red", "blue"), lty = 1, lwd=2)
dev.copy(png,'plot3.png')
dev.off()
Binary file added plot3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions plot4.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
dat<-read.csv("household_power_consumption.txt", sep=";", header = TRUE)

times<-strptime(paste(dat$Date,dat$Time), format = "%d/%m/%Y %H:%M:%S")

date=data.frame(as.Date(dat$Date, "%d/%m/%Y"))

dat$Date=as.Date(dat$Date, "%d/%m/%Y")

dat$newtimes=times

dat2<-dat[dat$Date>= "2007-02-01",]

dat3<-dat2[dat2$Date <= "2007-02-02",]

par(mfrow=c(2,2))
plot(dat3$newtimes,dat3$Global_active_power, type="l", ylab = "Global Active Power", xlab = "")
plot(dat3$newtimes,dat3$Voltage, type="l", ylab = "Voltage", xlab = "")
plot(dat3$newtimes,dat3$Sub_metering_1, type="l", ylab = "Energy sub metering", xlab = "")
points(dat3$newtimes,dat3$Sub_metering_2, type = "l", col = "red")
points(dat3$newtimes,dat3$Sub_metering_3, type="l", col = "blue")
legend(x ="top", legend = c("Sub_metering_1","Sub_metering_2","Sub_metering_3"), bty = "n", col = c("black", "red", "blue"), lty = 1, lwd=2)
plot(dat3$newtimes,dat3$Global_reactive_power, type="l", ylab = "Global Reactive Power", xlab = "")
dev.copy(png,'plot4.png')
dev.off()
Binary file added plot4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.