Toxigal
Toxigal

Reputation: 47

Grouped bar chart for intersection size in upset plot

I figured out how to make a grouped bar chart using ComplexUpset. I would like to label each bar as follows N=count (XX%) where the denominator of XX% is the total number of items in the group. I am able to get it to label one of the bars appropriately but can't get both bars labeled.

movies = as.data.frame(ggplot2movies::movies) %>%
  filter(mpaa %in% (c('R','PG'))) %>%
  head(2000)
genres = colnames(movies)[18:24]

R_N<-length(movies$title[which(movies$mpaa=="R")]) ## determine number of R rated movies in set
PG_N<-length(movies$title[which(movies$mpaa=="PG")])## determine number of PG rated movies in set


ComplexUpset::upset(
  movies,
  genres,
  width_ratio = 0.5,
  min_size = 10,
  set_sizes = FALSE,
  base_annotations = list(
    'Intersection size' = intersection_size(
      position = position_dodge(),
      mapping = aes(fill = mpaa,count=TRUE),
      text_mapping=aes(label=paste0(round(
        !!get_size_mode('exclusive_intersection')/R_N * 100
      ), '%')))
      )
    )
  

Upvotes: 0

Views: 8

Answers (0)

Related Questions