Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for heights to be universally scaled within the plot, not just the category #95

Open
shvaf opened this issue Apr 26, 2024 · 0 comments

Comments

@shvaf
Copy link

shvaf commented Apr 26, 2024

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
Example Ridgline

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant