I am making an upset diagram for the following data in percentages. This is a dummy example for my more complicated data.
x <- c(a=80, b=9.9, c=5, 'a&b'=0.1, 'a&c'=1.65, 'c&b'=3.35) upset(fromExpression(x), order.by = "freq")
I want these percentages to appear as decimal numbers and all the bars visible even if it is 0.1%. All the data is important in this plot.
library(UpSetR)
x <- c(a=80, b=9.9, c=5, 'a&b'=0.1, 'a&c'=1.65, 'c&b'=3.35)
upset(fromExpression(x), order.by = "freq", show.numbers = 'yes')

So you want two things:
percentages to appear as decimal numbers
bars visible even if it is 0.1%
You start by converting your vector of percentages to counts (integer) with fromExpression. So the input to upset is then a dataframe:
library(UpSetR)
x <- c(a=80, b=9.9, c=5, 'a&b'=0.1, 'a&c'=1.65, 'c&b'=3.35)
str(fromExpression(x))
#> 'data.frame': 98 obs. of 3 variables:
#> $ a: num 1 1 1 1 1 1 1 1 1 1 ...
#> $ b: num 0 0 0 0 0 0 0 0 0 0 ...
#> $ c: num 0 0 0 0 0 0 0 0 0 0 ...
upset internally then gets the labels from this data, so the link to your original percentages is no longer present inside upset.
Having labels as percentages, or some other custom labels, does not seem to be a supported option for the function upset from the UpSetR package at the moment.
There is the show.numbers argument but only allow to show those absolute frequencies on top of the bars (show.numbers = "yes" or show.numbers = "Yes") or not (any other value for show.numbers), here's the code bit involved:
https://github.com/hms-dbmi/UpSetR/blob/fe2812c8cbe87af18c063dcee9941391c836e7b2/R/MainBar.R#L130-L132
So I think you need to change that piece of code, i.e., the geom_text and aes_string, to use a different aesthetic mapping (your relative frequencies). So maybe ask the developer to do it?
Well, this ultimately depends on your y-axis dynamic range and the size of your plot, i.e., if the tallest bar is a lot greater than the shortest than it might be impossible to see both in the same chart (unless you make y-axis discontinuous).
I understand this is not really a solution to your problem but it is an answer that hopefully points you in the direction of the solution to your problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With