-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot4.R
42 lines (30 loc) · 871 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
30
31
32
33
34
35
36
37
38
39
40
41
42
# Check if we have data, if not load it!
source("load.data.R")
if (!exists("MEI")) {
NEI <- load.NEI()
}
if (!exists("SCC")) {
SCC <- load.SCC()
}
# Across the United States, how have emissions from coal combustion-related
# sources changed from 1999–2008?
library(dplyr)
library(ggplot2)
SCC.coal.which <- which(grepl("coal", SCC$Short.Name, ignore.case = TRUE))
SCC.coal <- SCC[SCC.coal.which,]
rm(SCC.coal.which)
NEI.coal <- inner_join(NEI, SCC.coal, by = "SCC") %>%
group_by(year) %>%
summarise(emissions=sum(Emissions))
p4 <-
qplot(data = NEI.coal,
x=year, y=emissions,
geom = c("point", "line"),
main = "Coal emissions across the United States",
xlab = "Year",
ylab = "Emissions in tons")
ggsave(plot = p4, filename = "plot4.png", width=10, height=10, dpi=100)
# clenup
rm(p4)
rm(SCC.coal)
rm(NEI.coal)