-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot4.R
34 lines (22 loc) · 1.09 KB
/
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
30
31
32
33
34
# Exploratory Data Analysis
# Across the United States, how have emissions from coal combustion-related sources changed from 1999-2008?
# Load ggplot2 library
library(ggplot2)
# upload data files
NEI <- readRDS("~/summarySCC_PM25.rds")
View(NEI)
SCC <- readRDS("~/Source_Classification_Code.rds")
View(SCC)
SCC.coal = SCC[grepl("coal", SCC$Short.Name, ignore.case=TRUE),]
merge <- merge(x=NEI, y=SCC.coal, by='SCC')
merge.sum <- aggregate(merge[, 'Emissions'], by=list(merge$year), sum)
colnames(merge.sum) <- c('Year', 'Emissions')
# Generate the graph in the same directory as the source code
png(filename='~/Course Project 2/plot4.png')
ggplot(data=merge.sum, aes(x=Year, y=Emissions/1000)) +
geom_line(aes(group=1, col=Emissions)) + geom_point(aes(size=2, col=Emissions)) +
ggtitle(expression('Total Emissions of PM'[2.5])) +
ylab(expression(paste('PM', ''[2.5], ' in kilotons'))) +
geom_text(aes(label=round(Emissions/1000,digits=2), size=2, hjust=1.5, vjust=1.5)) +
theme(legend.position='none') + scale_colour_gradient(low='black', high='red')
dev.off()