-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot6.R
23 lines (22 loc) · 990 Bytes
/
plot6.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
##Read the datasets
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
NEI$year<-factor(NEI$year)
##extract the vehicle related data
SCC_vehicles<-subset(SCC,Data.Category=='Onroad')$SCC
NEI_vehicle<-subset(NEI,NEI$SCC %in% SCC_vehicles)
NEI_vehicle_Baltimore<-subset(NEI_vehicle,NEI_vehicle$fips=="24510")
NEI_vehicle_LA<-subset(NEI_vehicle,NEI_vehicle$fips=="06037")
sums_Baltimore<-aggregate(NEI_vehicle_Baltimore$Emissions,
list(NEI_vehicle_Baltimore$year),sum)
sums_LA<-aggregate(NEI_vehicle_LA$Emissions,list(NEI_vehicle_LA$year),sum)
par(mfrow=c(1,2))
names(sums_Baltimore)<-c("year","emissions")
names(sums_LA)<-c("year","emissions")
plot(sums_Baltimore$year,sums_Baltimore$emissions,
main="Baltimore",
xlab="year",ylab="Emission(Tons)")
plot(sums_LA$year,sums_LA$emissions,
main="LA",
xlab="year",ylab="Emission(Tons)")
dev.copy(png,file="plot6.png")