-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot2.R
35 lines (24 loc) · 1.13 KB
/
plot2.R
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
32
33
34
35
# Have total emissions from PM2.5 decreased in the Baltimore City, Maryland (fips == "24510")
# from 1999 to 2008? Use the base plotting system to make a plot answering this question.
NEI.file <- "summarySCC_PM25.rds"
SCC.file <- "Source_Classification_Code.rds"
Baltimore.fip <- "24510"
message(paste("Reading ", NEI.file, " dataset"))
NEI <- readRDS(NEI.file)
message(paste("Reading ", SCC.file, " dataset"))
SCC <- readRDS(SCC.file)
message("Extracting Baltimore data")
NEI.Baltimore <- NEI[which(NEI$fips == Baltimore.fip),]
message("Calculating yearly total emissions")
NEI.Baltimore.total <- aggregate(list(emissions = NEI.Baltimore$Emissions), by=list(year = NEI.Baltimore$year), FUN = sum)
message("Plotting and saving file")
par(mar=c(5,5,6,3))
barplot((NEI.Baltimore.total$emissions/1000),
ylim=c(0, 4),
names.arg = c(as.character(NEI.Baltimore.total$year)),
col="red",
xlab = "Years",
ylab="PM2.5 Emissions (per 1000 tons)")
mtext(side=3, line=3, "PM2.5 Emissions in Baltimore City between 1999 and 2008", cex=1.2)
dev.copy(png, file = "plot2.png", width = 580, height = 580)
dev.off()