corybrunson / ggalluvial

ggplot2 extension for alluvial plots
http://corybrunson.github.io/ggalluvial/
GNU General Public License v3.0
499 stars 34 forks source link

filter out labels below threshold to limit overlap #95

Closed antoine4ucsd closed 2 years ago

antoine4ucsd commented 2 years ago

Hello I am trying to plot exhange between locations (from /to ) and it works fine with your package. However, when there are too many labels, I woul like to show the label ONLY those who account for > XX% , everything else remaining the same. For example below the plot is too dense: ggplot(data, aes(y = totalCount/sum(totalCount), axis1 = from, axis2 = to,label = after_stat(stratum))) + geom_alluvium(aes(fill = from),color = NA, na.rm = T,alpha=0.9) + geom_stratum(width = 1/5, color = "black", na.rm = TRUE) + geom_label_repel(stat = "stratum",size=4, label.size = 0, max.overlaps = getOption("ggrepel.max.overlaps", default = 40))

dense

so I am trying to only show labels when the total fraction for a given location is > 5% for example. I tried to create a new df2 df2$from=ifelse(df2$fraction_from<0.05," ",as.character(df2$from)) df2$to=ifelse(df2$fraction_to<0.05," ",as.character(df2$to)) and use it into the geom_label_repel(df2 ,...) --> this messed up the label order or to use label=ifelse(as.numeric(df$fraction) >5, after_stat(stratum), NA) --> error

can you help with that? I can share a dataset via email if you want. THANK YOU!

corybrunson commented 2 years ago

Hi @antoine4ucsd, thanks for raising the issue! Please have a look at the "Fix" section of the stratum-labeling vignette to see if the min.y parameter does what you want. I can get back to you in more detail Friday if this doesn't resolve the issue.

antoine4ucsd commented 2 years ago

it seems really promising!!! I would love to discuss further with you about optimizing my outputs for publication. thank you so much