-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot5.R
More file actions
54 lines (42 loc) · 1.18 KB
/
plot5.R
File metadata and controls
54 lines (42 loc) · 1.18 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#Reference UDFs
source("./udf.R")
#Define function for building the plot png file
plot5 <- function(dframes=NULL){
packages <- c("dplyr","ggplot2","sqldf")
packagechecks <- checkPackages(packages)
if(is.null(dframes)){
dframes <- loaddata()
}
pmdf <- data.frame(dframes[1])
summary <- data.frame(dframes[2])
#Begin Analysis
summary.baltimore <- subset(summary, summary$fips == "24510")
scc.mobile <- unlist(sqldf('Select "SCC"
from pmdf
where "SCC.Level.One" = "Mobile Sources"
order by "SCC"'))
summary.mobile <- summary.baltimore[summary.baltimore$SCC %in% scc.mobile
& summary.baltimore$type=="ON-ROAD", ]
mobile.by.year <- aggregate(summary.mobile$Emissions,
by = list(summary.mobile$year),
FUN = "sum")
mobile.by.year <- dplyr::rename(mobile.by.year,
yr = Group.1,
pm25 = x)
# Set bg color transparent
par(bg = "transparent")
# Start device
png(file = "plot5.png", width=1200, height=800)
# Draw plot 5
print({
qplot(yr, pm25,
data = mobile.by.year,
geom = c("point","smooth"),
method = "lm")
})
# Close the device
dev.off()
#Answer, They have decreased with the largest decrease from 1999 - 2002
}
#Call the Function
plot5()