Last active
April 7, 2022 17:34
-
-
Save kjhealy/8b3bdeda1cfc87b62d7020886416186a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```{r} | |
library(tidyverse) | |
library(here) | |
library(fs) | |
library(socviz) | |
``` | |
```{r} | |
here() | |
``` | |
```{r} | |
fnames <- dir_ls(here("results")) | |
df <- read_csv(fnames, id = "model") %>% | |
mutate(model = str_remove(model, "/Users/kjhealy/scratch/results/"), | |
model = str_remove(model, "_res.csv"), | |
model = case_when(model == "m5a" ~ "1980-1989", | |
model == "m5b" ~ "1990-1999", | |
model == "m5c" ~ "2000-2009", | |
model == "m5d" ~ "2010-2018"), | |
model = factor(model, levels = rev(c("1980-1989", "1990-1999", | |
"2000-2009", "2010-2018")), | |
ordered = TRUE)) | |
``` | |
```{r} | |
theme_set(theme_minimal()) | |
my_colors <- RColorBrewer::brewer.pal(8, "Blues")[4:8] | |
df %>% | |
filter(term %nin% "(Intercept)", | |
model %in% c("1990-1999", "2010-2018")) %>% | |
ggplot(mapping = aes(x = estimate, | |
xmin = conf.low, | |
xmax = conf.high, | |
y = reorder(term, estimate), | |
color = model)) + | |
# scale_color_manual(values = rev(my_colors)[c(2,4)]) + | |
geom_vline(xintercept = 0, color = "gray50") + | |
geom_pointrange(position = position_dodge(width = 0.7)) | |
``` | |
## Consider also plots like e.g. | |
```{r} | |
df <- read_csv(fnames, id = "model") %>% | |
mutate(model = str_remove(model, "/Users/kjhealy/scratch/results/"), | |
model = str_remove(model, "_res.csv"), | |
model = case_when(model == "m5a" ~ "1980-1989", | |
model == "m5b" ~ "1990-1999", | |
model == "m5c" ~ "2000-2009", | |
model == "m5d" ~ "2010-2018"), | |
model = factor(model, levels = c("1980-1989", "1990-1999", | |
"2000-2009", "2010-2018"), | |
ordered = TRUE)) | |
df %>% | |
filter(str_detect(term, "reltrad")) %>% | |
mutate(term = str_remove(term, "reltrad")) %>% | |
filter(term %nin% "Jewish") %>% | |
ggplot(mapping = aes(x = model, | |
ymin = conf.low, | |
ymax = conf.high, | |
y = estimate)) + | |
geom_hline(yintercept = 0, color = "gray40", linetype = "dotted") + | |
geom_line(aes(group = term)) + | |
geom_pointrange() + | |
facet_wrap(~ reorder(term, estimate), ncol = 1) | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment