-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot3.R
More file actions
38 lines (24 loc) · 1.25 KB
/
plot3.R
File metadata and controls
38 lines (24 loc) · 1.25 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
# Of the four types of sources indicated by the type (point, nonpoint, onroad, nonroad) variable,
# which of these four sources have seen decreases in emissions from 1999-2008 for Baltimore City?
# Which have seen increases in emissions from 1999-2008? Use the ggplot2 plotting system to make a plot answer this question.
library(ggplot2)
NEI.file <- "summarySCC_PM25.rds"
SCC.file <- "Source_Classification_Code.rds"
Baltimore.fip <- "24510"
message(paste("Reading ", NEI.file, " dataset"))
NEI <- readRDS(NEI.file)
message(paste("Reading ", SCC.file, " dataset"))
SCC <- readRDS(SCC.file)
message("Extracting Baltimore data")
NEI.Baltimore <- NEI[which(NEI$fips == Baltimore.fip),]
message("Calculating yearly total emissions")
NEI.Baltimore.total <- aggregate(list(emissions = NEI.Baltimore$Emissions), by=list(year = NEI.Baltimore$year, type = NEI.Baltimore$type), FUN = sum)
message("Plotting and saving file")
m <- melt(NEI.Baltimore.total, id=c("year", "type"))
ggplot(data=m, aes(x=year, y=value, colour=type)) +
geom_line() +
ylab("PM2.5 Emission in tons") +
xlab("Year") +
ggtitle("PM2.5 Emissions in Baltimore City between 1999 and 2008 by type")
dev.copy(png, file = "plot3.png", width = 780, height = 580)
dev.off()