-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot4.R
More file actions
29 lines (24 loc) · 1 KB
/
Copy pathplot4.R
File metadata and controls
29 lines (24 loc) · 1 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
# url to file
url <- "https://d396qusza40orc.cloudfront.net/exdata%2Fdata%2FNEI_data.zip"
if (!file.exists("data.zip")) {
download.file(url = url, destfile = "data.zip", method = "curl")
}
# read the files inside .zip
unzip("data.zip", list = TRUE)
NEI <- readRDS(unzip("data.zip", "summarySCC_PM25.rds"))
SCC <- readRDS(unzip("data.zip", "Source_Classification_Code.rds"))
names(NEI)
library(dplyr)
library(ggplot2)
combustion_coal <- SCC %>%
filter(grepl("Comb",SCC.Level.One) & grepl("Coal", SCC.Level.Three))
pm25_combcoal <- NEI %>%
filter(SCC %in% combustion_coal$SCC) %>%
group_by(year) %>%
summarise(Emissions = sum(Emissions))
png(filename = "plot4.png")
ggplot(data = pm25_combcoal, aes(factor(as.character(year)), Emissions)) +
geom_bar(stat = "identity") +
ggtitle(label = expression("Total PM"[2.5]*" emissions from coal combustion")) +
xlab("Year")
dev.off()