Reputation: 11
When I assigning a logarithmic scale to “Intersection size” using ComplexUpset library the bars disappear. Is there a way around?
Upvotes: 1
Views: 377
Reputation: 15379
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
)
Upvotes: 0