Last active
November 15, 2022 20:02
-
-
Save stuvet/258a6d9ad028d31a5ef32b0a2ce71ed5 to your computer and use it in GitHub Desktop.
Example Concentration Plot
This file contains hidden or 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
library(ggplot2) | |
library(ggtext) | |
library(dplyr) | |
.data <- tibble( | |
prior = rexp(10000, 1), | |
posterior = rlnorm(10000, 0.25, 0.2) | |
) |> | |
tidyr::pivot_longer(cols = everything()) |> | |
mutate(name = factor(name)) | |
subtitle <- "<span style='font-size:16pt'> | |
<span style = 'color:#8F8A99;'> | |
<strong>Prior</strong> | |
</span> | |
& | |
<span style='color:#008080'> | |
<strong>Posterior</strong> | |
</span> | |
</span>" | |
ggplot(.data, aes(x = value, colour = name, fill = name)) + | |
geom_histogram(data = subset(.data, name == 'prior'), alpha = 0.3, colour = '#8F8A99', fill = '#8F8A99', bins = 50) + | |
geom_histogram(data = subset(.data, name == 'posterior'), alpha = 0.7, colour = '#008080', fill = '#008080', bins = 50) + | |
labs( | |
title = 'How much did the posterior update relative to the prior?', | |
subtitle = subtitle, | |
y = "", | |
x = "σ" | |
) + | |
theme( | |
plot.title.position = 'plot', | |
plot.caption.position = 'plot', | |
text = element_text(family = 'Oxygen', size = 16), | |
legend.position = 'none', | |
axis.text.y = element_blank(), | |
axis.ticks.y = element_blank(), | |
panel.background = element_rect(fill = 'transparent'), | |
plot.subtitle = element_markdown(lineheight=1.5) | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment