library(tidyverse)
library(targets)
library(scales)
library(patchwork)
library(here)
# Generated via random.org
set.seed(8316)
# Load data
# Need to use this withr thing because tar_read() and tar_load() need to see the
# _targets folder in the current directory, but this .Rmd file is in a subfolder
::with_dir(here::here(), {
withrsource(tar_read(plot_funs))
tar_load(survey_results)
tar_load(sim_excel_final)
tar_load(sim_final)
tar_load(giving_aggregate)
tar_load(giving_per_capita)
})
<- tribble(
religion_lookup ~Q5.10, ~religion,
1, "Catholic",
2, "Protestant",
3, "Christian Orthodox",
4, "Jewish",
5, "Muslim",
6, "Sikh",
7, "Hindu",
8, "Buddhist",
9, "Atheist",
10, "Other"
)
<- nrow(survey_results)
n_respondents
<- survey_results %>%
religions count(Q5.10) %>%
left_join(religion_lookup, by = "Q5.10") %>%
arrange(n) %>%
mutate(religion = fct_inorder(religion)) %>%
mutate(percent = n / n_respondents)
ggplot(religions, aes(x = n, y = religion)) +
geom_col(fill = clrs_okabe_ito$reddish_purple) +
scale_x_continuous(sec.axis = sec_axis(~. / n_respondents, labels = percent)) +
labs(x = "Number of respondents", y = NULL) +
theme_ngo()
<- survey_results %>%
religion_others filter(!is.na(Q5.10_TEXT)) %>%
mutate(Q5.10_TEXT = str_to_lower(Q5.10_TEXT)) %>%
count(Q5.10_TEXT) %>%
arrange(desc(n))
religion_others
## # A tibble: 91 x 2
## Q5.10_TEXT n
## <chr> <int>
## 1 christian 34
## 2 agnostic 21
## 3 none 18
## 4 spiritual 9
## 5 baptist 8
## 6 born again christian 4
## 7 pagan 4
## 8 wiccan 4
## 9 lds 3
## 10 methodist 3
## # … with 81 more rows
Based on data from Giving USA, philanthropy in the United states continues to increase, both in aggregate and per capita.
ggplot(giving_aggregate, aes(x = Year, y = `Total donations`)) +
geom_line(size = 1, color = clrs_okabe_ito$orange) +
scale_x_continuous(breaks = seq(1980, 2015, 5)) +
scale_y_continuous(labels = dollar, breaks = seq(100, 450, 50)) +
coord_cartesian(ylim = c(100, 450)) +
labs(x = NULL, y = "Billions of dollars") +
theme_ngo()
ggplot(giving_per_capita, aes(x = Year, y = `Average giving`)) +
geom_line(size = 1, color = clrs_okabe_ito$sky_blue) +
scale_x_continuous(breaks = seq(2000, 2014, 2)) +
scale_y_continuous(labels = dollar, breaks = seq(1750, 2750, 250)) +
coord_cartesian(ylim = c(1750, 2750)) +
labs(x = NULL, y = "Average annual donation") +
theme_ngo()
<- sim_final %>%
plot_income_issue group_by(org_issue, persona_income) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Issue area") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_issue, 15)),
x = avg_share, color = fct_rev(persona_income))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002)),
breaks = seq(0, 0.06, 0.02)) +
scale_color_manual(values = clrs_ngo_pairs[[1]], guide = FALSE) +
coord_cartesian(xlim = c(0, 0.06)) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_income_funding group_by(org_funding, persona_income) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Funding sources") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_funding, 10)),
x = avg_share, color = fct_rev(persona_income))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.06)) +
scale_color_manual(values = clrs_ngo_pairs[[1]], guide = FALSE) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_income_relationship mutate(persona_income = fct_recode(persona_income,
"< $61,372/year" = "Lower income",
"> $61,372/year" = "Higher income")) %>%
group_by(org_relationship, persona_income) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Relationship with host government") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_relationship, 10)),
x = avg_share, color = fct_rev(persona_income))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.003))) +
coord_cartesian(xlim = c(0, 0.1)) +
scale_color_manual(values = clrs_ngo_pairs[[1]],
guide = guide_legend(reverse = TRUE, nrow = 1,
override.aes = list(size = 0.25,
linetype = 0))) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(str_wrap(facet, 50))) +
theme_ngo() +
theme(panel.grid.major.y = element_blank(),
legend.key.width = unit(0.5, "lines"))
<- sim_excel_final %>%
plot_income_relationship_extreme mutate(persona_income = fct_recode(persona_income,
"$50,000/year" = "Lower income",
"$100,000/year" = "Higher income"),
org_relationship = fct_recode(org_relationship,
"Under crackdown" = "Crackdown")) %>%
group_by(org_relationship, persona_income) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Relationship with host government") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_relationship, 10)),
x = avg_share, color = fct_rev(persona_income))) +
geom_pointrange(size = 0.75, fatten = 1.5, linetype = "21", pch = 2,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.1)) +
scale_color_manual(values = clrs_ngo_pairs[[1]],
guide = guide_legend(reverse = TRUE, nrow = 1,
override.aes = list(size = 0.25,
linetype = 0))) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(str_wrap(facet, 50))) +
theme_ngo() +
theme(panel.grid.major.y = element_blank(),
legend.key.width = unit(0.5, "lines"))
<- ((plot_income_issue + labs(x = NULL)) +
plot_income + labs(x = NULL))) /
(plot_income_funding + plot_income_relationship_extreme)
(plot_income_relationship
plot_income
<- sim_final %>%
plot_education_issue group_by(org_issue, persona_education) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Issue area") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_issue, 15)),
x = avg_share, color = fct_rev(persona_education))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.06)) +
scale_color_manual(values = clrs_ngo_pairs[[2]], guide = FALSE) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_education_funding group_by(org_funding, persona_education) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Funding sources") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_funding, 10)),
x = avg_share, color = fct_rev(persona_education))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.06)) +
scale_color_manual(values = clrs_ngo_pairs[[2]], guide = FALSE) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_education_relationship group_by(org_relationship, persona_education) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Relationship with host government") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_relationship, 10)),
x = avg_share, color = fct_rev(persona_education))) +
geom_pointrange(size = 0.75, fatten = 1.5,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.1)) +
scale_color_manual(values = clrs_ngo_pairs[[2]],
guide = guide_legend(reverse = TRUE, ncol = 1,
override.aes = list(size = 0.25,
linetype = 0)),
labels = label_wrap(15)) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(str_wrap(facet, 20))) +
theme_ngo() +
theme(panel.grid.major.y = element_blank(),
legend.key.width = unit(0.5, "lines"))
<- plot_education_issue + plot_education_funding +
plot_education + guide_area() +
plot_education_relationship plot_layout(guides = "collect", ncol = 4)
plot_education
<- sim_final %>%
plot_religion_issue group_by(org_issue, persona_religion) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Issue area") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_issue, 15)),
x = avg_share, color = fct_rev(persona_religion))) +
geom_pointrange(size = 0.75, fatten = 1.5, pch = 17,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.06)) +
scale_color_manual(values = clrs_ngo_pairs[[4]], guide = FALSE) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_religion_funding group_by(org_funding, persona_religion) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Funding sources") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_funding, 10)),
x = avg_share, color = fct_rev(persona_religion))) +
geom_pointrange(size = 0.75, fatten = 1.5, pch = 17,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.06)) +
scale_color_manual(values = clrs_ngo_pairs[[4]], guide = FALSE) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(facet)) +
theme_ngo() +
theme(panel.grid.major.y = element_blank())
<- sim_final %>%
plot_religion_relationship group_by(org_relationship, persona_religion) %>%
summarize(avg_share = mean(share)) %>%
mutate(facet = "Relationship with host government") %>%
ggplot(aes(y = fct_rev(str_wrap_factor(org_relationship, 10)),
x = avg_share, color = fct_rev(persona_religion))) +
geom_pointrange(size = 0.75, fatten = 1.5, pch = 17,
aes(xmin = 0, xmax = ..x..), position = position_dodge(width = 0.5)) +
scale_x_continuous(labels = percent_format(accuracy = 1), expand = expansion(add = c(0, 0.002))) +
coord_cartesian(xlim = c(0, 0.1)) +
scale_color_manual(values = clrs_ngo_pairs[[4]],
guide = guide_legend(reverse = TRUE, ncol = 1,
override.aes = list(size = 0.25,
linetype = 0)),
labels = label_wrap(20)) +
labs(x = "Average donation share", y = NULL, color = NULL) +
facet_wrap(vars(str_wrap(facet, 20))) +
theme_ngo() +
theme(panel.grid.major.y = element_blank(),
legend.key.width = unit(0.5, "lines"))
<- plot_religion_issue + plot_religion_funding +
plot_religion + guide_area() +
plot_religion_relationship plot_layout(guides = "collect", ncol = 4)
plot_religion
<- (plot_education_issue + labs(x = NULL)) +
plot_education_religion + labs(x = NULL)) +
(plot_education_funding + labs(x = NULL)) +
(plot_education_relationship guide_area() +
+
plot_religion_issue +
plot_religion_funding +
plot_religion_relationship plot_layout(guides = "collect", ncol = 4)
plot_education_religion
::session_info() devtools
## ─ Session info ─────────────────────────────────────────────────────────────────────────
## setting value
## version R version 4.0.3 (2020-10-10)
## os macOS Big Sur 10.16
## system x86_64, darwin17.0
## ui X11
## language (EN)
## collate en_US.UTF-8
## ctype en_US.UTF-8
## tz America/New_York
## date 2021-04-21
##
## ─ Packages ─────────────────────────────────────────────────────────────────────────────
## ! package * version date lib source
## P assertthat 0.2.1 2019-03-21 [?] CRAN (R 4.0.0)
## P backports 1.2.1 2020-12-09 [?] CRAN (R 4.0.2)
## P broom 0.7.5 2021-02-19 [?] CRAN (R 4.0.2)
## P bslib 0.2.4 2021-01-25 [?] CRAN (R 4.0.2)
## P cachem 1.0.4 2021-02-13 [?] CRAN (R 4.0.2)
## callr 3.6.0 2021-03-28 [1] CRAN (R 4.0.2)
## P cellranger 1.1.0 2016-07-27 [?] CRAN (R 4.0.0)
## cli 2.4.0 2021-04-05 [1] CRAN (R 4.0.2)
## P codetools 0.2-18 2020-11-04 [?] CRAN (R 4.0.2)
## P colorspace 2.0-0 2020-11-11 [?] CRAN (R 4.0.2)
## P crayon 1.4.1 2021-02-08 [?] CRAN (R 4.0.2)
## P data.table 1.14.0 2021-02-21 [?] CRAN (R 4.0.2)
## P DBI 1.1.1 2021-01-15 [?] CRAN (R 4.0.2)
## P dbplyr 2.1.0 2021-02-03 [?] CRAN (R 4.0.2)
## P desc 1.3.0 2021-03-05 [?] CRAN (R 4.0.2)
## devtools 2.4.0 2021-04-07 [1] CRAN (R 4.0.2)
## P digest 0.6.27 2020-10-24 [?] CRAN (R 4.0.2)
## P dplyr * 1.0.5 2021-03-05 [?] CRAN (R 4.0.2)
## P ellipsis 0.3.1 2020-05-15 [?] CRAN (R 4.0.0)
## P evaluate 0.14 2019-05-28 [?] CRAN (R 4.0.0)
## P fansi 0.4.2 2021-01-15 [?] CRAN (R 4.0.2)
## P farver 2.1.0 2021-02-28 [?] CRAN (R 4.0.2)
## P fastmap 1.1.0 2021-01-25 [?] CRAN (R 4.0.2)
## P forcats * 0.5.1 2021-01-27 [?] CRAN (R 4.0.2)
## P fs 1.5.0 2020-07-31 [?] CRAN (R 4.0.2)
## P generics 0.1.0 2020-10-31 [?] CRAN (R 4.0.2)
## P ggplot2 * 3.3.3 2020-12-30 [?] CRAN (R 4.0.2)
## P glue 1.4.2 2020-08-27 [?] CRAN (R 4.0.2)
## P gtable 0.3.0 2019-03-25 [?] CRAN (R 4.0.0)
## P haven 2.3.1 2020-06-01 [?] CRAN (R 4.0.2)
## P here * 1.0.1 2020-12-13 [?] CRAN (R 4.0.2)
## P highr 0.8 2019-03-20 [?] CRAN (R 4.0.0)
## P hms 1.0.0 2021-01-13 [?] CRAN (R 4.0.2)
## P htmltools 0.5.1.1 2021-01-22 [?] CRAN (R 4.0.2)
## P httr 1.4.2 2020-07-20 [?] CRAN (R 4.0.2)
## P igraph 1.2.6 2020-10-06 [?] CRAN (R 4.0.2)
## P jquerylib 0.1.3 2020-12-17 [?] CRAN (R 4.0.2)
## P jsonlite 1.7.2 2020-12-09 [?] CRAN (R 4.0.2)
## P knitr 1.31 2021-01-27 [?] CRAN (R 4.0.2)
## P labeling 0.4.2 2020-10-20 [?] CRAN (R 4.0.2)
## P lifecycle 1.0.0 2021-02-15 [?] CRAN (R 4.0.2)
## P lubridate 1.7.10 2021-02-26 [?] CRAN (R 4.0.2)
## P magrittr 2.0.1 2020-11-17 [?] CRAN (R 4.0.2)
## P memoise 2.0.0 2021-01-26 [?] CRAN (R 4.0.2)
## P modelr 0.1.8 2020-05-19 [?] CRAN (R 4.0.2)
## P munsell 0.5.0 2018-06-12 [?] CRAN (R 4.0.0)
## P patchwork * 1.1.1 2020-12-17 [?] CRAN (R 4.0.2)
## P pillar 1.5.1 2021-03-05 [?] CRAN (R 4.0.2)
## P pkgbuild 1.2.0 2020-12-15 [?] CRAN (R 4.0.2)
## P pkgconfig 2.0.3 2019-09-22 [?] CRAN (R 4.0.0)
## pkgload 1.2.1 2021-04-06 [1] CRAN (R 4.0.2)
## P prettyunits 1.1.1 2020-01-24 [?] CRAN (R 4.0.0)
## P processx 3.5.1 2021-04-04 [?] CRAN (R 4.0.2)
## P ps 1.6.0 2021-02-28 [?] CRAN (R 4.0.2)
## P purrr * 0.3.4 2020-04-17 [?] CRAN (R 4.0.0)
## P R6 2.5.0 2020-10-28 [?] CRAN (R 4.0.2)
## P Rcpp 1.0.6 2021-01-15 [?] CRAN (R 4.0.2)
## P readr * 1.4.0 2020-10-05 [?] CRAN (R 4.0.2)
## P readxl 1.3.1 2019-03-13 [?] CRAN (R 4.0.0)
## remotes 2.3.0 2021-04-01 [1] CRAN (R 4.0.2)
## renv 0.13.0 2021-02-24 [1] CRAN (R 4.0.2)
## P reprex 1.0.0 2021-01-27 [?] CRAN (R 4.0.2)
## P rlang 0.4.10 2020-12-30 [?] CRAN (R 4.0.2)
## P rmarkdown 2.7 2021-02-19 [?] CRAN (R 4.0.2)
## P rprojroot 2.0.2 2020-11-15 [?] CRAN (R 4.0.2)
## P rstudioapi 0.13 2020-11-12 [?] CRAN (R 4.0.2)
## P rvest 1.0.0 2021-03-09 [?] CRAN (R 4.0.2)
## P sass 0.3.1 2021-01-24 [?] CRAN (R 4.0.2)
## P scales * 1.1.1 2020-05-11 [?] CRAN (R 4.0.0)
## P sessioninfo 1.1.1 2018-11-05 [?] CRAN (R 4.0.0)
## P stringi 1.5.3 2020-09-09 [?] CRAN (R 4.0.2)
## P stringr * 1.4.0 2019-02-10 [?] CRAN (R 4.0.0)
## P targets * 0.2.0 2021-02-27 [?] CRAN (R 4.0.2)
## P testthat 3.0.2 2021-02-14 [?] CRAN (R 4.0.2)
## P tibble * 3.1.0 2021-02-25 [?] CRAN (R 4.0.2)
## P tidyr * 1.1.3 2021-03-03 [?] CRAN (R 4.0.2)
## P tidyselect 1.1.0 2020-05-11 [?] CRAN (R 4.0.0)
## P tidyverse * 1.3.0 2019-11-21 [?] CRAN (R 4.0.0)
## P usethis 2.0.1 2021-02-10 [?] CRAN (R 4.0.2)
## P utf8 1.1.4 2018-05-24 [?] CRAN (R 4.0.0)
## P vctrs 0.3.7 2021-03-29 [?] CRAN (R 4.0.2)
## P withr 2.4.1 2021-01-26 [?] CRAN (R 4.0.2)
## P xfun 0.22 2021-03-11 [?] CRAN (R 4.0.2)
## P xml2 1.3.2 2020-04-23 [?] CRAN (R 4.0.0)
## P yaml 2.2.1 2020-02-01 [?] CRAN (R 4.0.0)
##
## [1] /Users/andrew/Dropbox (Personal)/Research collaboration/Global policy special issue/renv/library/R-4.0/x86_64-apple-darwin17.0
## [2] /private/var/folders/4d/ynkkj1nj0yj0lt91mkw2mq100000gn/T/Rtmp0tLEGE/renv-system-library
##
## P ── Loaded and on-disk path mismatch.
writeLines(readLines(file.path(Sys.getenv("HOME"), ".R/Makevars")))
## # http://dirk.eddelbuettel.com/blog/2017/11/27/#011_faster_package_installation_one
## VER=
## CCACHE=ccache
## CC=$(CCACHE) gcc$(VER)
## CXX=$(CCACHE) g++$(VER)
## CXX11=$(CCACHE) g++$(VER)
## CXX14=$(CCACHE) g++$(VER)
## FC=$(CCACHE) gfortran$(VER)
## F77=$(CCACHE) gfortran$(VER)
##
## CXX14FLAGS=-O3 -march=native -mtune=native -fPIC
Social trust across issue area