forked from rdpeng/ExData_Plotting1
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
Latest commit
31 lines (30 loc) · 1.17 KB
/
Copy pathplot4.R
File metadata and controls
31 lines (30 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
data<- read.csv('household_power_consumption.txt', sep=';',
colClasses='character')
data<-data[data$Date%in% c('1/2/2007', '2/2/2007'),]
data<- within(data, {
Global_active_power<- as.numeric(Global_active_power)
Global_reactive_power<- as.numeric(Global_reactive_power)
Voltage<- as.numeric(Voltage)
Sub_metering_1<- as.numeric(Sub_metering_1)
Sub_metering_2<- as.numeric(Sub_metering_2)
Sub_metering_3<- as.numeric(Sub_metering_3)
t<- strptime(paste(Date, Time), '%d/%m/%Y %H:%M:%S')
})
png(filename="plot4.png", width=480, height=480)
par(mfcol= c(2,2))
with(data,
plot(t, Global_active_power, type='l', xlab='',
ylab='Global Active Power'))
with(data, {
plot(t, Sub_metering_1, type='l', xlab='',
ylab='Energy sub metering')
lines(t, Sub_metering_2, col='red')
lines(t, Sub_metering_3, col='blue')
legend('topright', lwd=1, col=c('black', 'red', 'blue'),
legend=c('Sub_metering_1', 'Sub_metering_2', 'Sub_metering_3'))
with(data,
plot(t, Voltage, type='l', xlab='datetime'))
with(data,
plot(t, Global_reactive_power, type='l', xlab='datetime'))
})
dev.off()