complex-upset
complex-upset copied to clipboard
Adjusting “Intersection size” to display the counts of each group when the bars are filled
Hi,
I am trying to produce a graph similar to your example 3.2 ("Fill the bars"), but also displaying the counts of each colored bar.
Some time ago, I managed to do it by using counts=TRUE
and text = list(position = position_stack(vjust = 0.0))
in intersection_size()
. I was getting something like that:
However, in the current version, I do not get the expected behaviour anymore. For example if I try it on the vignette example as follows,
upset(
movies,
genres,
base_annotations=list(
'Intersection size'=intersection_size(
counts=TRUE,
mapping=aes(fill=mpaa),
text = list(position = position_stack(vjust = 0.0))
)
),
width_ratio=0.1
)
I get this:
I would be interested to know if there is a new way to adjust the parameters of intersection_size()
to obtain a graph that looks like the first one.
Thank you!
Context
ComplexUpset version: 1.1.0
R session information
R version 4.0.3 (2020-10-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17763)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252 LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.3 ComplexUpset_1.1.0
loaded via a namespace (and not attached):
[1] magrittr_2.0.1 tidyselect_1.1.0 munsell_0.5.0 colorspace_2.0-0 R6_2.5.0
[6] rlang_0.4.10 dplyr_1.0.4 ggplot2movies_0.0.1 patchwork_1.1.1 tools_4.0.3
[11] grid_4.0.3 gtable_0.3.0 xfun_0.19 tinytex_0.27 DBI_1.1.1
[16] withr_2.3.0 ellipsis_0.3.1 digest_0.6.27 assertthat_0.2.1 tibble_3.0.4
[21] lifecycle_1.0.0 crayon_1.4.1 farver_2.0.3 purrr_0.3.4 vctrs_0.3.6
[26] glue_1.4.2 labeling_0.4.2 compiler_4.0.3 pillar_1.4.7 generics_0.1.0
[31] scales_1.1.1 pkgconfig_2.0.3
Thank you for opening this. I would love to have an example on how to do that in the documentation. Indeed, the underlying data structure changed and the usage needs to be adjusted. It should be possible with:
upset(
movies,
genres,
base_annotations=list(
'Intersection size'=intersection_size(
counts=FALSE,
mapping=aes(fill=mpaa),
) + stat_summary(
fun=sum,
geom='text',
position=position_stack(vjust = 0.0),
aes(label=..y..)
)
),
width_ratio=0.1,
min_size=10
)
But it is not currently possible because there is an issue in ggplot2 when using stat_summary
and position_stack
with text:
https://github.com/tidyverse/ggplot2/issues/4367. I think that fixing the issue in ggplot2 would the best way forward.
Thanks for the clarification, I will definitively try that whenever the ggplot2 issue is fixed.
@krassowski Is there any other work around for this issue? Also seeing this issue and couldn't work my way around it.
No, I don't believe so. But you could try to fix it upstream in ggplot2, the maintainers already identified the likely issue: https://github.com/tidyverse/ggplot2/issues/4367#issuecomment-792391336. This would likely help a lot of people and might be a very simple fix.
Good news, https://github.com/tidyverse/ggplot2/issues/4367 was fixed upstream, which means it should work wit the next patch release of ggplot2 (hopefully 3.3.6).
Great news, thanks!
Is there a way to replace the counts with the percentages?
@richardstoeckl yes, see https://krassowski.github.io/complex-upset/articles/Examples_R.html#showing-percentages and https://krassowski.github.io/complex-upset/articles/Examples_R.html#display-percentages but this issue was about counts so I am closing it.