用 R VennDiagram 填充颜色:"Unexpected parameter length for 'fill'"
Color Fill with R VennDiagram: "Unexpected parameter length for 'fill'"
我使用维恩图可视化 values_one
和 values_two
之间的重叠。
默认结果是黑白的,但我想用颜色填充它。基于this tutorial,我使用RColorBrewer
;但是,我收到以下错误消息:
Error in VennDiagram::draw.pairwise.venn(area1 = length(x[1]), area2 = length(x[[2]]), :
Unexpected parameter length for 'fill'
我做错了什么,我该如何解决?
感谢您的帮助!
# ------------------
# reproducible values
# ------------------
values_one <- c("Physical Review B", "IFAC Papersonline", "Journal Of High Energy Physics",
"Physical Review Letters", "Nuclear Fusion", "Physics Letters B")
values_two <- c("Lecture Notes", "Optics Infobase Conference Papers", "Physical Review B", "IFAC Papersonline", "Journal Of High Energy Physics", "Physical Review Letters")
# ------------------
# create VennDiagram
# ------------------
library("VennDiagram")
library("RColorBrewer")
myCol <- brewer.pal(3, "Pastel2")
venn.diagram(x = list(values_one, values_two)
, category.names = c("WoS", "Scopus")
, filename = paste0(filePath, "venn2019.png")
, output=T
, fill=myCol)
尝试将 myCol
限制为两个十六进制代码而不是三个。
编辑:
因为RColorBrewer::brewer.pal对可以直接选择的颜色数量有下限(n > 2),如果你只想要一种或两种颜色,你首先需要指定你想要的调色板使用和 then 子集特定的十六进制代码。例如像这样:
myCol <- brewer.pal(8, "Pastel2")[c(1, 2)]
myCol <- brewer.pal(8, "Pastel2")[c(1, 8)] # Or any other nice-looking combination
我使用维恩图可视化 values_one
和 values_two
之间的重叠。
默认结果是黑白的,但我想用颜色填充它。基于this tutorial,我使用RColorBrewer
;但是,我收到以下错误消息:
Error in VennDiagram::draw.pairwise.venn(area1 = length(x[1]), area2 = length(x[[2]]), : Unexpected parameter length for 'fill'
我做错了什么,我该如何解决?
感谢您的帮助!
# ------------------
# reproducible values
# ------------------
values_one <- c("Physical Review B", "IFAC Papersonline", "Journal Of High Energy Physics",
"Physical Review Letters", "Nuclear Fusion", "Physics Letters B")
values_two <- c("Lecture Notes", "Optics Infobase Conference Papers", "Physical Review B", "IFAC Papersonline", "Journal Of High Energy Physics", "Physical Review Letters")
# ------------------
# create VennDiagram
# ------------------
library("VennDiagram")
library("RColorBrewer")
myCol <- brewer.pal(3, "Pastel2")
venn.diagram(x = list(values_one, values_two)
, category.names = c("WoS", "Scopus")
, filename = paste0(filePath, "venn2019.png")
, output=T
, fill=myCol)
尝试将 myCol
限制为两个十六进制代码而不是三个。
编辑:
因为RColorBrewer::brewer.pal对可以直接选择的颜色数量有下限(n > 2),如果你只想要一种或两种颜色,你首先需要指定你想要的调色板使用和 then 子集特定的十六进制代码。例如像这样:
myCol <- brewer.pal(8, "Pastel2")[c(1, 2)]
myCol <- brewer.pal(8, "Pastel2")[c(1, 8)] # Or any other nice-looking combination