我想用R绘制一个venn图,因为我使用的是venn包,因为它允许接受4到5个以上的组(作为我找到的大多数包)。
当我想改变标签的颜色(内外标签)时,问题就来了。我还没有找到任何方法来修改它们。如果要使用深色背景,则黑色标签(默认颜色)不可见。我想再用一种颜色。
最近,venn包有一个逻辑的ggplot参数,但我认为它只用于路径美学。使用ggsave = TRUE将简化使用ggsave的保存过程,并将其赋值为变量(它不使用ggsave= FALSE,但它不接受custom_color变量,并通过错误进行操作)。
这是一个示例代码:
x = rep(1, 20)
d = data.frame('A'=x, 'B'=x, 'C'=x, 'D'=x, 'E'=x, 'F'=x)
custom_color = c('blue', 'red', 'orange', 'green', 'yellow', 'pink')
library(venn)
library(grDevices)
png(filename = 'venn_plot.png', width = 2, height = 2,
units = 'in', res = 150, bg = 'black')
venn(d, ggplot = FALSE,
zcolor = custom_color, col = custom_color,
opacity = .5, box = FALSE)
dev.off()

library(ggplot2)
v = venn(d, ggplot = TRUE,
zcolor = custom_color, col = custom_color,
opacity = .5, box = FALSE)
v
Error: Aesthetics must be either length 1 or the same as the data (1848): fill发布于 2020-04-22 14:41:09
您可以将venn图捕获为网格对象,然后直接修改该对象的参数。举个例子,我把标签变成红色,背景变成黑色。View可以很好地帮助确定要更改的参数。
library(gridGraphics)
library(grid)
venn(d, ggplot = FALSE,
zcolor = custom_color, col = custom_color,
opacity = .5, box = FALSE)
grid.echo()
venn_plot <- grid.grab()
venn_plot$children$`graphics-plot-1-text-2`$gp$col <- "red"
venn_plot$children$`graphics-background`$gp$fill <- "black"
grid.draw(venn_plot)

https://stackoverflow.com/questions/61364911
复制相似问题