Open acpguedes opened 4 years ago
Hi Aureliano,
thank you for your interest in my package. The feature that you are asking about is not directly supported by ggupset
. This was a conscious design decision because for me the defining feature of the Upset plot is the clever representation of overlaps on the x-axis.
You can however make the a plot equivalent to UpsetR
if you use ggupset
and combine it with cowplot
or patchwork
. Both packages allow you to arrange multiple ggplots. This way you can make the Set Size plot separately and add it on the lower left side of the main ggupset
plot.
I created a small example to demonstrate the approach. You can play around with the margins and rel_heights
/ rel_widths
to optimize the appearence, but this should help you get started:
library(tidyverse)
library(ggupset)
main_plot <- tidy_movies %>%
distinct(title, year, length, .keep_all=TRUE) %>%
ggplot(aes(x=Genres)) +
geom_bar() +
scale_x_upset(n_intersections = 20)
side_plot <- tidy_movies %>%
select(Genres) %>%
unnest(cols = Genres) %>%
count(Genres) %>%
mutate(Genres = fct_reorder(as.factor(Genres), n)) %>%
ggplot(aes(y = n, x = Genres)) +
geom_col() +
coord_flip() +
scale_y_reverse() +
xlab("") + ylab("") +
theme(axis.ticks.y = element_blank(), axis.text.y = element_blank())
cowplot::plot_grid(
cowplot::plot_grid(NULL, side_plot + theme(plot.margin = unit(c(1, -5, -5, 1), "pt")), ncol = 1, rel_heights = c(2.15, 1)),
main_plot, nrow = 1, rel_widths = c(1, 3)
)
#> Warning: Removed 100 rows containing non-finite values (stat_count).
Created on 2020-02-29 by the reprex package (v0.3.0)
I will keep this issue open as a reference for other people who might have a similar issue in the future.
Thank you for your example.
You may also want to check out my package: https://github.com/krassowski/complex-upset which does exactly what @const-ae suggests, glueing many ggplots under the hood, using patchwork
.
Hi Michał, thanks for sharing. That looks like an interesting package to easily assemble more complex UpSet plots :)
Related question: I'd like to be able to show the number of intersections above each bar. Currently I'm using UpSetR::upset()
and would like to switch my code over to using ggupset::scale_x_upset()
instead. I'm having a bit of trouble figuring out how to do this. Am I missing something in the documentation, or is there not currently an easy way to add numeric labels above each bar?
Hey Michael, try this https://stackoverflow.com/questions/26553526/how-to-add-frequency-count-labels-to-the-bars-in-a-bar-graph-using-ggplot2/26556180#26556180 answer. The good thing about ggupset is that you can use all the tricks from ggplot, it does however mean that sometimes typical patterns are a bit opaque. Maybe I should add this specific example to the documentation, because this question has come a few times already :)
I added a new section to the README that explains how to add the numbers on top https://github.com/const-ae/ggupset#adding-numbers-on-top
Perfect thanks @const-ae !
Hi,
How I add information about the total size of a set at the left of categories names, as the UpSetR does.
I'd like to use ggupset to generate a plot equal to upsetr, as the image below.