Author(s): Borja V. Sorli Sanz - borjavss@gmail.com - @borjavss -
Fine particulate matter \( PM^(2.5) \) is an ambient air pollutant for which there is strong evidence that it is harmful to human health. In the United States, the Environmental Protection Agency EPA is tasked with setting national ambient air quality standards for fine PM and for tracking the emissions of this pollutant into the atmosphere. Approximatly every 3 years, the EPA releases its database on emissions of \( PM^(2.5) \). This database is known as the National Emissions Inventory (NEI). You can read more information about the NEI at the EPA National Emissions Inventory web site.
The data for this assignment are available from the web site as a single zip file: Data (29Mb)
The data is provided as a compressed zip file, we should unzip it.
unzip("exdata-data-NEI_data.zip", overwrite = T) # unziping
## Warning: error 1 in extracting from zip file
The zip file contains two files:
| fips: | A five-digit number (represented as a string) indicating the U.S. county | ||
| SCC: | The name of the source as indicated by a digit string (see source code classification table) | ||
| Pollutant: | A string indicating the pollutant | ||
| Emissions: | Amount of PM2.5 emitted, in tons | ||
| type: | The type of source (point, non-point, on-road, or non-road) | ||
| year: | The year of emissions recorded |
head(NEI)
## fips SCC Pollutant Emissions type year
## 4 09001 10100401 PM25-PRI 15.714 POINT 1999
## 8 09001 10100404 PM25-PRI 234.178 POINT 1999
## 12 09001 10100501 PM25-PRI 0.128 POINT 1999
## 16 09001 10200401 PM25-PRI 2.036 POINT 1999
## 20 09001 10200504 PM25-PRI 0.388 POINT 1999
## 24 09001 10200602 PM25-PRI 1.490 POINT 1999
head(SCC, n = 3)
## SCC Data.Category
## 1 10100101 Point
## 2 10100102 Point
## 3 10100201 Point
## Short.Name
## 1 Ext Comb /Electric Gen /Anthracite Coal /Pulverized Coal
## 2 Ext Comb /Electric Gen /Anthracite Coal /Traveling Grate (Overfeed) Stoker
## 3 Ext Comb /Electric Gen /Bituminous Coal /Pulverized Coal: Wet Bottom
## EI.Sector Option.Group Option.Set
## 1 Fuel Comb - Electric Generation - Coal
## 2 Fuel Comb - Electric Generation - Coal
## 3 Fuel Comb - Electric Generation - Coal
## SCC.Level.One SCC.Level.Two
## 1 External Combustion Boilers Electric Generation
## 2 External Combustion Boilers Electric Generation
## 3 External Combustion Boilers Electric Generation
## SCC.Level.Three
## 1 Anthracite Coal
## 2 Anthracite Coal
## 3 Bituminous/Subbituminous Coal
## SCC.Level.Four Map.To Last.Inventory.Year
## 1 Pulverized Coal NA NA
## 2 Traveling Grate (Overfeed) Stoker NA NA
## 3 Pulverized Coal: Wet Bottom (Bituminous Coal) NA NA
## Created_Date Revised_Date Usage.Notes
## 1
## 2
## 3
You can read each of the two files using the readRDS() function in R. For example, reading in each file can be done with the following code:
## This first line will likely take a few seconds. Be patient!
NEI <- readRDS("summarySCC_PM25.rds")
SCC <- readRDS("Source_Classification_Code.rds")
as long as each of those files is in your current working directory (check by calling dir() and see if those files are in the listing).
The overall goal of this document is to explore the National Emissions Inventory database and see what it say about fine particulate matter pollution in the United states over the 10-year period 1999-2008. Our code downloads data automatically.
We will address the following questions/tasks in our exploratory analysis. For each question/task we will need to make a single plot.
years <- c("1999", "2002", "2005", "2008")
means <- vector() #initializing data
for (i in years) {
means[i] <- mean(NEI$Emissions[which(NEI$year == i)], na.rm = TRUE)
}
# basic plot
barplot(means, col = rainbow(20, start = 0, end = 1), main = "Mean PM_2.5 emissions (Tons)")
means.baltimore <- vector() # preparing plot data
for (i in years) {
means.baltimore[i] <- mean(NEI$Emissions[which(NEI$year == i & NEI$fips ==
"24510")], na.rm = TRUE)
}
# basic plot
barplot(means.baltimore, col = terrain.colors(2), main = "Mean PM_2.5 emissions (Tons)\n in Baltimore city")
data.baltimore <- NEI[which((NEI$fips == "24510") & (NEI$Emissions < 1000)),
] #initializing data
# plotting:
require("ggplot2")
## Loading required package: ggplot2
g2 <- ggplot(data.baltimore, aes(year, Emissions))
g2 + geom_point(aes(color = type), size = 10, alpha = 0.3) + facet_grid(. ~
type) + geom_smooth(size = 2, color = "black", linetype = 1, method = "lm",
se = FALSE)
# creating plot data:
d.tmp1 <- NEI[NEI$SCC %in% SCC[grep("Coal", SCC$EI.Sector), 1], ]
d.tmp2 <- SCC[, c(1, 4)]
data.coal <- merge(d.tmp1, d.tmp2, by.x = "SCC", by.y = "SCC")[, c(4, 6, 7)]
# plotting:
require("ggplot2")
g4 <- ggplot(data.coal, aes(x = year, y = Emissions))
g4 + geom_point(aes(color = EI.Sector), size = 10, alpha = 0.3) + facet_grid(. ~
EI.Sector) + geom_smooth(size = 2, color = "black", linetype = 1, method = "lm",
se = FALSE)
# reorganizing plot data:
d.tmp1 <- NEI[NEI$SCC %in% SCC[grep("Mobile", SCC$EI.Sector), 1], ]
d.tmp3 <- d.tmp1[which(d.tmp1$fips == "24510"), ]
d.tmp2 <- SCC[, c(1, 4)]
d5 <- merge(d.tmp3, d.tmp2, by.x = "SCC", by.y = "SCC")[, c(4, 6, 7)]
# removing outliers and sources out of our interest:
d5[d5$Emissions > 15, ] <- NA
d5 <- d5[which(d5$EI.Sector != "Mobile - Commercial Marine Vessels"), ]
d5 <- d5[which(d5$EI.Sector != "Mobile - Aircraft"), ]
# plotting:
require("lattice")
## Loading required package: lattice
xyplot(Emissions ~ year | EI.Sector, d5, layout = c(4, 2), ylab = "Emissions",
xlab = "years", panel = function(x, y) {
panel.xyplot(x, y)
panel.lmline(x, y, lty = 1, col = "red")
par.strip.text = list(cex = 0.8)
}, as.table = T)
# reorganizing plot data:
data <- rbind(d.baltim <- NEI[which(NEI$fips == "24510"), ], d.lac <- NEI[which(NEI$fips ==
"06037"), ])
data$fips[which(data$fips == "24510")] <- "Baltimore City"
data$fips[which(data$fips == "06037")] <- "Los Angeles County"
names(data)[1] <- "Cities"
# plotting:
require("ggplot2")
g6 <- ggplot(data, aes(x = year, y = Emissions, fill = Cities))
g6 + geom_bar(stat = "identity", position = position_dodge())
Regarding Fine Particule levels (\( PM^(2.5) \)) arround US, different r open library packages and different types of graphics are used to accomplish different goals proposed. Remark that data levels are given each 3 years, for Environmental Protection Agency (EPA). These codes script could be modified to solve future questions.