1

我想使用ComplexUpset包创建一个 UpSet 图。我想手动为交叉矩阵中的点着色以匹配集合的颜色。

这是我到目前为止所尝试的:

movies <- read.csv( system.file("extdata", "movies.csv", package = "UpSetR"), header=T, sep=";" )

ComplexUpset::upset(movies, colnames(movies)[3:5], name='genre', width_ratio=0.1, 
  matrix=(intersection_matrix(geom=geom_point()) +
            scale_color_manual(values = c('Action'='red', 'Adventure'='blue', 'Children'='yellow'))), 
  queries=list(upset_query(set='Action', fill='red'),
               upset_query(set='Adventure', fill='blue'),
               upset_query(set='Children', fill='yellow')))

输出

添加 scale_color_manual 只会导致额外的点图例,这是我不想要的。我希望交叉矩阵本身中的点为红色,“冒险”的点为蓝色,“儿童”的点为黄色。连接点的线段应保持黑色。

4

1 回答 1

1

这些点不会改变颜色,因为您正在传递fill(不是color)到upset_query; 如果您愿意,您可以继续使用fill,但在这种情况下,您还需要更改点的形状,以便它们具有要填充的区域,这可以使用shape='circle filled'(还有其他形状!)。

同样,scale_color_manual在普通的 ggplot2 中,这不是一个完美的选择,但鉴于它被 ComplexUpset 覆盖,这实际上是一个好主意,但您需要自定义 override.aes 以使其按预期显示。

library(ComplexUpset)
library(ggplot2)

upset(
    movies,
    colnames(movies)[3:5],
    name='genre',
    width_ratio=0.1,
    matrix=(
        intersection_matrix(geom=geom_point(shape='circle filled', size=3))
        + scale_color_manual(
            values=c('Action'='red', 'Adventure'='blue', 'Children'='yellow'),
            guide=guide_legend(override.aes=list(shape='circle'))
        )
    ),
    queries=list(
        upset_query(set='Action', fill='red'),
        upset_query(set='Adventure', fill='blue'),
        upset_query(set='Children', fill='yellow')
    )
)

用圆圈填充的解决方案

或者,您可以简单地传递colorfill但我认为该fill选项提供更好的视觉效果。

于 2021-09-22T15:37:37.927 回答