I have a presentation that includes morbidity categories overtime and I'm using ridgeline bins to display it. I would like to have the heights of bins to be comparable between the groups instead of being comparable within groups. Any insight on how to accomplish this?
In the attached pictures, the shortest heights of each only have 1 count but appear to be different sizes. See R code below
library(tidyverse)
library(ggridges)
remotes::install_github("wilkelab/ggridges")
d <- tribble(~grp, ~day, ~count,
"A", 0, 3,
"A", 1, 0,
"A", 3, 1,
"A", 6, 1,
"B", 0, 5,
"B", 4, 3,
"B", 5, 3,
"C", 0, 1,
"C", 4, 1,
"C", 6,10,
) %>% mutate(grp=factor(grp)) %>%
mutate(wt_col=count/sum(count)) #%>% uncount(count) # if we don't use the "weights" aesthetic, we have to uncount
d %>% ggplot(aes(x=day, y=grp, fill=grp, weight=wt_col)) + geom_density_ridges(bandwidth=0.5)
d %>% uncount(count) %>% ggplot(aes(x=day, y=grp, fill=grp)) + geom_density_ridges(bandwidth=0.1, stat="binline")
d %>% ggplot(aes(x=day, y=grp, fill=grp, weight=wt_col)) + geom_density_ridges(aes(height=after_stat(density)), stat="density",bw=0.1)
I have a presentation that includes morbidity categories overtime and I'm using ridgeline bins to display it. I would like to have the heights of bins to be comparable between the groups instead of being comparable within groups. Any insight on how to accomplish this?
In the attached pictures, the shortest heights of each only have 1 count but appear to be different sizes. See R code below