ggdist
ggdist copied to clipboard
integrating textpath with stat_halfeye
I am trying to use {geomtextpath} to label different parts of a distribution visually and am having trouble figuring out how to blend the two packages together.
i am using stat_function as my solution in with the geom set to textpath.
any ideas how i can achieve this? thanks!
plot_tbl <- tibble::tibble(
dist = "lnorm",
label = c('>=3', '>=4', '>=6', '>=8'),
logmean = c(log(7),log(9), log(12), log(18)),
logsd = log(3.5)
)
plot_tbl |>
ggplot() +
ggdist::stat_halfeye(aes(
y = factor(label), dist = dist, arg1 = logmean, arg2 = logsd,
fill = after_stat(x < 6)), show.legend = FALSE) +
stat_function(
aes(y = '>8'),
geom = 'textpath',
fun = dlnorm,
label = 'aaa',
size = 5,
vjust = -0.2,
hjust = 0.1,
args = list(meanlog = log(18), sdlog = log(3.5))
) +
scale_x_log10(breaks = 10^seq(-5,7, by = 2))
Yeah this is hard --- would probably need something like #217 so that thickness values could be translated into y values for that geom.