在 Complex Upset 中通过设置颜色手动为点着色
Manual coloring of dots by set color in Complex Upset
我想使用 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 只会导致绘制额外的点图例,这是我不想要的。我希望在交集矩阵本身中,'Action' 的点为红色,'Adventure' 的点为蓝色,'Children' 的点为黄色。连接点的线段应保持黑色。
这些点不会改变颜色,因为您将 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')
)
)
或者,您可以简单地传递 color
除了 fill
,但我认为 fill
选项提供更好的视觉效果。
我想使用 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 只会导致绘制额外的点图例,这是我不想要的。我希望在交集矩阵本身中,'Action' 的点为红色,'Adventure' 的点为蓝色,'Children' 的点为黄色。连接点的线段应保持黑色。
这些点不会改变颜色,因为您将 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')
)
)
或者,您可以简单地传递 color
除了 fill
,但我认为 fill
选项提供更好的视觉效果。