-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
38 lines (24 loc) · 1.21 KB
/
plot4.R
File metadata and controls
38 lines (24 loc) · 1.21 KB
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
# Across the United States, how have emissions from coal combustion-related sources
# changed from 1999-2008?
library(ggplot2)
NEI.file <- "summarySCC_PM25.rds"
SCC.file <- "Source_Classification_Code.rds"
message(paste("Reading ", NEI.file, " dataset"))
NEI <- readRDS(NEI.file)
message(paste("Reading ", SCC.file, " dataset"))
SCC <- readRDS(SCC.file)
message("Extracting coal combustion related data")
SCC.CoalCombustion <- SCC[grepl("[Cc]oal", SCC$EI.Sector) & grepl("[Cc]omb", SCC$EI.Sector), "SCC"]
NEI.CoalCombustion <- NEI[NEI$SCC %in% SCC.CoalCombustion, ]
message("Calculating yearly total emissions")
NEI.CoalCombustion.total <- aggregate(list(emissions = NEI.CoalCombustion$Emissions), by=list(year = NEI.CoalCombustion$year), FUN = sum)
message("Plotting and saving file")
par(mar=c(5,5,5,5))
barplot(t(as.matrix(NEI.CoalCombustion.total$emissions/1000)),
ylim=c(0, 600),
names.arg = c(as.character(NEI.CoalCombustion.total$year)),
col="red",
xlab="Years", ylab=" Emissions (in thousands tons)")
mtext(side=3, line=2, "Coal combustion-related emissions in US between 1999 and 2008", cex=1.2)
dev.copy(png, file = "plot4.png", width = 680, height = 580)
dev.off()