When I assigning a logarithmic scale to “Intersection size” using ComplexUpset library the bars disappear. Is there a way around?
Asked
Active
Viewed 99 times
1
-
1Welcome to SO! If you need answers, you have to provide us with all the information needed to understand the problem. Please give us a [minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Jan Apr 17 '22 at 09:21
1 Answers
0
This is because in ggplot2's geom_bar
does not play well with log10 scale/transform when using stat other than "identity"
(see Bar plot with log scales). CompelxUpset
plots each data point individually to allow for colouring each observation separately. You can revert to plotting pre-summarised data by passing the following function as data to geom_bar
:
presence = ComplexUpset:::get_mode_presence('exclusive_intersection')
summarise_values = function(df) {
aggregate(
as.formula(paste0(presence, '~ intersection')),
df,
FUN=sum
)
}
and then plot it, starting with the example:
library(ComplexUpset)
library(ggplot2)
movies = as.data.frame(ggplot2movies::movies)
movies[movies$mpaa == '', 'mpaa'] = NA
movies = na.omit(movies)
genres = colnames(movies)[18:24]
to get log10 transform only:
upset(
movies,
genres,
base_annotations=list(
'log10(intersection size)'=(
ggplot()
+ geom_bar(data=summarise_values, stat='identity', aes(y=!!presence))
+ ylab('Intersection size')
+ scale_y_continuous(trans='log10')
)
),
min_size=5,
width_ratio=0.1
)
to get log10 on axis too:
upset(
movies,
genres,
base_annotations=list(
'log10(intersection size)'=(
ggplot()
+ geom_bar(
data=summarise_values,
stat='identity',
aes(y=log10(!!presence))
)
+ ylab('log10(intersection size)')
)
),
width_ratio=0.1
)

krassowski
- 13,598
- 4
- 60
- 92