krassowski / complex-upset

A library for creating complex UpSet plots with ggplot2 geoms
MIT License
469 stars 28 forks source link

How can I change the labels in the UpSet plot? #167

Open bagcik1lumc opened 1 year ago

bagcik1lumc commented 1 year ago

How can I change the labels "Set size" and "Intersection size" into something custom?

upset(data = head(file, 100), intersect = colnames(file), 
      name="",
      width_ratio = 0.125,
      ylab="",) +
  labs(title = "",
       caption = "")
krassowski commented 1 year ago
upset(
    movies, genres,
    base_annotations=list('Either here'=intersection_size() + ylab('Or by adding ylab')),
    set_sizes=upset_set_size() + ylab('My set size')
)

image

krassowski commented 1 year ago

I am going to close this one as answered. Thanks for trying complex-upset!

bagcik1lumc commented 1 year ago

Last, how can I remove the x-axis ticks on the left bottom plot, the y-axis ticks on the bar plot and show percentages on the left bottom plot? This concerns upset_set_size() I believe.

krassowski commented 1 year ago

There is an example on modifying ticks under https://krassowski.github.io/complex-upset/articles/Examples_R.html#rotate-labels

As for percentages on set sizes, see below:

upset(
    movies, genres, width_ratio=0.5, max_size=100, min_size=15, wrap=TRUE,
    set_sizes=(
        upset_set_size(
            mapping=aes(y=..count../max(..count..)),
        )
        + scale_y_reverse(labels=scales::percent_format())
        + ylab('Size relative to the largest')
    )
)

image

krassowski commented 1 year ago

Reopening as these examples should be added to the documentation.

bagcik1lumc commented 1 year ago

I've seen the example, but it does not explain how to remove the y-ticks in the base_annotations. If I add theme(axis.ticks.y=element_blank()) it will remove the whole bar plot

krassowski commented 1 year ago

If I add theme(axis.ticks.y=element_blank()) it will remove the whole bar plot

This would be unexpected. It works for me. Can you provide an example?

upset(
    movies, genres,
    base_annotations=list(
       'Size'=(
           intersection_size()
           + theme(axis.ticks.y=element_blank())
        )
    )
)

image

bagcik1lumc commented 1 year ago
upset(
  head(M4_BinaryMatrix, 100),
  colnames(M4_BinaryMatrix),
  base_annotations = list('Intersection size'=intersection_size(text_mapping=aes(label=paste0(round(
    !!get_size_mode('exclusive_intersection')/!!get_size_mode('inclusive_union') * 100
  ), '%'))) 
  + ylab("") 
  + theme(axis.ticks.y=element_blank(), plot.background=element_rect(fill='#E5D3B3'))),

  name = "",
  annotations = list(),
  themes = upset_themes,
  stripes = upset_stripes(),
  labeller = identity,
  height_ratio = 0.5,
  width_ratio = 0.3,
  wrap = FALSE,
  set_sizes=(
    upset_set_size(
      mapping=aes(y=..count../max(..count..)),
    )
    + scale_y_reverse(labels=scales::percent_format())
    + ylab("")
    + theme(axis.text.x = element_blank())
    ),
  mode = "distinct",
  queries = list(),
  guides = NULL,
  encode_sets = TRUE,
  matrix = intersection_matrix(),
  n_intersections=5
  ) +
  labs(title = "",
       caption = "")
bagcik1lumc commented 1 year ago

image

I would also like to add percentages next or onto the bars, instead of on the x-scale.

krassowski commented 1 year ago

Just swap ..count.. in the 4.4 Display counts example with the formula of choice for percentage, e.g. ..count../max(..count..).