-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.R
96 lines (88 loc) · 4.25 KB
/
maps.R
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
map_setup <- function()
{
CShape <- read_rds('cshape.Rds') # read county shape geometries, from census beauru
CShape$State <- CShape$state_name
CShape$County <- CShape$county_name
CShape$Geography <- sprintf("%s, %s", CShape$county_name, CShape$state_name)
CanFoo <- Cancer
CanFoo.incidenceMean <- mean(CanFoo$avgAnnCount[CanFoo$avgAnnCount!=1962.667684] / CanFoo$popEst2015[CanFoo$avgAnnCount!=1962.667684] * 100000)
CanFoo$avgAnnCount[CanFoo$avgAnnCount==1962.667684] <- CanFoo.incidenceMean * CanFoo$popEst2015[CanFoo$avgAnnCount==1962.667684] / 100000
CanFoo$incidenceRate <- CanFoo$avgAnnCount / CanFoo$popEst2015 * 100000
CanFoo$deathRate <- CanFoo$deathRate
CanMap <<- left_join(CanFoo, CShape, by = 'Geography') # export to global scope
CanMap.deathLimits <<- c(min(CanFoo$deathRate),
max(CanFoo$deathRate))
CanMap.incidenceLimits <<- c(min(CanFoo$incidenceRate),
max(CanFoo$incidenceRate))
print('Loaded Cancer Map Data')
}
map_ca_deathRate <- function()
{
CanMap %>%
filter(state %in% c('CA')) %>%
ggplot(aes(lon, lat, group = group, fill = deathRate)) +
theme_wsj() +
theme(legend.position = 'bottom',
text = element_text(size = 12, family = family),
title = element_text(size = 16, family = family),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) +
ggtitle('Death Rate per 100K Population',
subtitle = 'California') +
geom_polygon(color = NA, size = 0.05) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradientn(colors = rev(brewer.pal(11, 'RdYlGn')),
limits = CanMap.deathLimits)
}
map_wv_ky_deathRate <- function()
{
CanMap %>%
filter(state %in% c('WV','KY')) %>%
ggplot(aes(lon, lat, group = group, fill = deathRate)) +
theme_wsj() +
theme(legend.position = 'bottom',
text = element_text(size = 12, family = family),
title = element_text(size = 16, family = family),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) +
ggtitle('Death Rate per 100K Population',
subtitle = 'Kansas + West Virginia') +
geom_polygon(color = NA, size = 0.05) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradientn(colors = rev(brewer.pal(11, 'RdYlGn')),
limits = CanMap.deathLimits)
}
map_us_deathRate <- function()
{
CanMap %>%
ggplot(aes(lon, lat, group = group, fill = deathRate)) +
theme_wsj() +
theme(legend.position = 'bottom',
text = element_text(size = 12, family = family),
title = element_text(size = 16, family = family),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) +
ggtitle('Death Rate per 100K Population',
subtitle = 'United States') +
geom_polygon(color = NA, size = 0.05) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradientn(colors = rev(brewer.pal(11, 'RdYlGn')),
limits = CanMap.deathLimits)
}
map_us_incidenceRate <- function()
{
CanMap %>%
ggplot(aes(lon, lat, group = group, fill = incidenceRate)) +
theme_wsj() +
theme(legend.position = 'bottom',
text = element_text(size = 12, family = family),
title = element_text(size = 16, family = family),
plot.title = element_text(hjust = 0.5),
plot.subtitle = element_text(hjust = 0.5)) +
ggtitle('Incidence Rate per 100K Population',
subtitle = 'United States') +
geom_polygon(color = NA, size = 0.05) +
coord_map(projection = "albers", lat0 = 39, lat1 = 45) +
scale_fill_gradientn(colors = rev(brewer.pal(11, 'RdYlGn')),
limits = CanMap.incidenceLimits)
}