-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot6.R
More file actions
63 lines (50 loc) · 1.69 KB
/
plot6.R
File metadata and controls
63 lines (50 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
#Reference UDFs
source("./udf.R")
#Define function for building the plot png file
plot6 <- 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.la <- subset(summary, summary$fips %in% c("24510", "06037"))
summary.baltimore.la <- mutate(summary.baltimore.la,
city = ifelse(fips == "24510", "Baltimore", "LA"))
scc.mobile <- unlist(sqldf('Select "SCC"
from pmdf
where "SCC.Level.One" = "Mobile Sources"
order by "SCC"'))
summary.mobile <- summary.baltimore.la[summary.baltimore.la$SCC %in% scc.mobile
& summary.baltimore.la$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 = "plot6.png", width=1200, height=800)
# Draw plot 5
print({
qplot(yr, pm25,
data = mobile.by.year,
geom = c("point","smooth"),
method = "lm")
g <- qplot(year, Emissions, data = summary.baltimore.la, geom = c("point","smooth"), method = "lm", facets = .~city)
g + geom_point() + coord_cartesian(ylim = (c(0,150)))
})
# Close the device
dev.off()
#Answer, Clearly LA has diminished emissions much more than Baltimore,
#but I suspect it's correlated to the number of cars,
#so to see which city has minimized the most per car on the road,
#one would need to take the emissions changes as a
#function of the number of cars on the road
}
#Call the Function
plot6()