Skip to content

Instantly share code, notes, and snippets.

@MattCowgill
Created January 25, 2024 04:05
Show Gist options
  • Save MattCowgill/26c9efdb30a814ea10c40046da9228fc to your computer and use it in GitHub Desktop.
Save MattCowgill/26c9efdb30a814ea10c40046da9228fc to your computer and use it in GitHub Desktop.
library(tidyverse)
cols <- c("#57aed7",
"#fab649",
"#c51954")
n_obs <- 1000
fake_data <- tibble(`Group A` = rnorm(n_obs, -1),
`Group B` = rnorm(n_obs, 0),
`Group C` = rnorm(n_obs, 1)) |>
pivot_longer(everything(),
names_to = "series")
fake_data |>
ggplot(aes(x = value,
fill = series,
col = series)) +
geom_vline(xintercept = 0,
linewidth = 0.25) +
geom_density(alpha = 0.1) +
ggdirectlabel::geom_richlegend(aes(label = series),
size = 18 / .pt) +
scale_fill_manual(values = cols) +
scale_colour_manual(values = cols) +
scale_y_continuous(expand = expansion(c(0, 0.05))) +
theme_minimal(base_size = 18) +
labs(y = "Density",
x = "Some continuous variable") +
theme(panel.grid = element_blank(),
panel.border = element_rect(
linetype = 1,
size = 0.5,
colour = seek_black,
fill = NA
),
legend.position = "none")
@MattCowgill
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment