-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot4.R
29 lines (23 loc) · 832 Bytes
/
plot4.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
##Set Working Directory
wd <- getwd()
##Library Calls
library(ggplot2)
##Read Data
NEI <- readRDS(file.path(wd,"exdata-data-NEI_data/summarySCC_PM25.rds"))
SCC <- readRDS(file.path(wd,"exdata-data-NEI_data/Source_Classification_Code.rds"))
#Coal Data
coal <- grepl("Fuel Comb.*Coal", SCC$EI.Sector)
coal_sources <- SCC[coal,]
#Coal Emissions Data
coal_emissions <- NEI[(NEI$SCC %in% coal_sources$SCC), ]
#Group For Each Year
coal_emissions <- aggregate(Emissions ~ year, data = coal_emissions, FUN = sum)
##GGPLOT2 Plot
g <- ggplot(coal_emissions, aes(x = factor(year), y = Emissions)) +
geom_bar(stat = "identity") +
xlab("Year") +
ylab(expression('Total PM'[2.5]*' Emissions')) +
ggtitle('EMISSIONS FROM COAL COMBUSTION SOURCES')
png("plot4.png", height = 480, width = 480)
print(g)
dev.off()