-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop_map.R
92 lines (72 loc) · 3.22 KB
/
pop_map.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
require(tidycensus)
require(ggplot2)
require(rayshader)
require(scales)
require(ggthemes)
require(sf)
require(dplyr)
require(colorspace)
census_api_key(key = Sys.getenv('census'))
vars <- load_variables(2020, "pl")
total_pop <- get_decennial(year = 2020, variables = "P1_001N", state = 42, county = 3, geography = "block group", geometry = TRUE) %>%
mutate(area = st_area(geometry),
area = as.numeric(area),
pop_density = value / area)
muni_pop <- get_decennial(year = 2020, variables = "P1_001N", state = 42, county = 3, geography = "county subdivision")
mp <- ggplot(data = total_pop, aes(fill = value, color = value)) +
geom_sf() +
theme_map() +
labs(fill = "Population", color = "Population") +
theme(legend.position="bottom")
mp
plot_gg(mp, multicore=TRUE, width=5 ,height=5, scale=250)
render_movie("img/alco_blckgrp.mp4", frames = 720, fps=30, zoom=0.6, fov = 30)
render_snapshot(clear = TRUE)
den <- ggplot(data = total_pop, aes(fill = pop_density, color = pop_density)) +
geom_sf(color = NA) +
theme_map() +
labs(fill = "Population Density") +
scale_fill_distiller(palette = "Blues", direction = 0) +
scale_color_distiller(palette = "Blues", direction = 0) +
theme(legend.position="bottom")
den
render_snapshot(clear = TRUE)
plot_gg(den, multicore=TRUE, width=8 ,height=8, scale=250)
render_snapshot(title_text = "Allegheny County Pop. Density")
save_3dprint("alo_densitry.stl", clear=TRUE)
plot_gg(den, multicore=TRUE, width=5 ,height=5, scale=250)
render_movie("img/alco_den_blckgrp.mp4", frames = 720, fps=30, zoom=0.6, fov = 30, phi = 25, title_text = "Allegheny County Pop. Density", title_color = "black")
render_snapshot(clear = TRUE)
pop_muni <- get_decennial(year = 2020, variables = "P1_001N", state = 42, county = 3, geography = "county subdivision", geometry = TRUE) %>%
mutate(area = st_area(geometry),
area = as.numeric(area),
pop_density = value / area)
muni <- ggplot(data = pop_muni, aes(fill = value)) +
geom_sf() +
theme_map() +
labs(fill = "Population")
plot_gg(muni, multicore=TRUE, width=5 ,height=5, scale=250)
render_movie("img/alco_muni.mp4", frames = 720, fps=30, zoom=0.6, fov = 30)
render_snapshot(clear = TRUE)
pop_pa <- get_decennial(year = 2020, variables = "P1_001N", state = 42, geography = "block group", geometry = TRUE) %>%
mutate(area = st_area(geometry),
area = as.numeric(area),
pop_density = value / area)
pa <- ggplot(data = pop_pa, aes(fill = value, color = value)) +
geom_sf() +
theme_map() +
labs(fill = "Population", color = "Population") +
theme(legend.position="bottom")
plot_gg(pa, multicore=TRUE, width=5 ,height=5, scale=250)
render_movie("img/pa_blckgrp.mp4", frames = 720, fps=30, zoom=0.85, fov = 30)
render_snapshot(clear = TRUE)
pa_den <- ggplot(data = pop_pa, aes(fill = pop_density)) +
geom_sf(color = NA) +
theme_map() +
labs(fill = "Population Density") +
scale_fill_distiller(palette = "Blues") +
theme(legend.position="bottom")
plot_gg(pa_den, multicore=TRUE, width=5 ,height=5, scale=250)
render_movie("img/pa_den_blckgrp.mp4", frames = 720, fps=30, zoom=.45, fov = 30, phi = 20, title_text = "Pennsylvania Population Density", title_color = "black")
render_snapshot(clear = TRUE)
rgl::rgl.close()