-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtil-shadowtext.R
112 lines (100 loc) · 2.61 KB
/
til-shadowtext.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Load Packages -----------------------------------------------------------
library(tidyverse)
library(shadowtext)
library(scales)
# Import Data -------------------------------------------------------------
population_projection <-
read_rds("population_projection.rds")
# Create Function ---------------------------------------------------------
population_projection_plot <- function(town_to_plot, county_to_plot) {
population_projection |>
filter(location %in% c(town_to_plot, county_to_plot, "Connecticut")) |>
mutate(location = fct(
location,
levels = c("Connecticut", county_to_plot, town_to_plot)
)) |>
ggplot(aes(
x = year,
y = pct,
color = location,
group = location
)) +
geom_point(size = 2) +
geom_line(show.legend = FALSE) +
labs(color = NULL) +
facet_wrap(
vars(age_group),
nrow = 1
) +
scale_y_continuous(
limits = c(0, 0.4),
labels = percent_format(1)
) +
scale_color_manual(
values = c(
# town_to_plot = "#9f3515",
# county_to_plot = "#fbbfb8",
# "Connecticut" = "#c4c4c4"
"#c4c4c4",
"#fbbfb8",
"#9f3515"
)
) +
guides(color = guide_legend(reverse = TRUE)) +
theme_minimal() +
theme(
panel.grid.minor = element_blank(),
panel.grid.major.x = element_blank(),
legend.position = "bottom",
strip.text = element_text(
face = "italic",
size = 13,
color = "grey40"
),
legend.text = element_text(
size = 13,
color = "grey40"
),
axis.title = element_blank(),
axis.text = element_text(
size = 13,
color = "grey40"
)
)
}
# Plot Hartford -----------------------------------------------------------
population_projection_plot(
town_to_plot = "Hartford",
county_to_plot = "Hartford County"
) +
geom_text(
data = population_projection |> filter(location == "Hartford"),
nudge_y = 0.03,
aes(
label = pct_formatted
)
)
# Plot Stamford -----------------------------------------------------------
population_projection_plot(
town_to_plot = "Stamford",
county_to_plot = "Fairfield County"
) +
geom_text(
data = population_projection |> filter(location == "Stamford"),
nudge_y = 0.03,
aes(
label = pct_formatted
)
)
population_projection_plot(
town_to_plot = "Stamford",
county_to_plot = "Fairfield County"
) +
geom_shadowtext(
data = population_projection |> filter(location == "Stamford"),
bg.color = "white",
nudge_y = 0.03,
aes(
label = pct_formatted
)
)