例如,將 A ∩ B 設為紅色,將其他所有內容設為白色。我附上了我當前代碼和維恩圖的影像。
install.packages("ggplot2")
install.packages("ggVennDiagram")
library(ggplot2)
library(ggVennDiagram)
## Creating a Venn Diagram
# use data frame as input
test = list(A = 1:1,B = 1:1)
# create a Venn diagram and display all sets
ggVennDiagram(test,label = c("none"))
scale_fill_gradient(low = "blue",high = "black")
theme(legend.position = "none",plot.background = element_rect(fill = "steelblue"),
panel.border = element_rect(fill = NA),plot.margin = margin(10, 10, 10, 10))

uj5u.com熱心網友回復:
ggVennDiagram沒有明確設計用于繪制集合成員關系圖,但可以這樣做。如果您使用以下設定:
library(ggVennDiagram)
library(ggplot2)
test = list(A = 1:1, B = 1:1)
p <- ggVennDiagram(test,label = c("none"))
scale_color_manual(values = c("black", "black"))
theme(legend.position = "none",
panel.border = element_rect(fill = NA, size = 2),
plot.margin = margin(10, 10, 10, 10))
p$layers[[1]]$mapping <- aes(fill = name)
然后您可以像這樣輕松地指定會員/非會員區域:首先,指定要指示區域是否在集合內的顏色:
yes <- "lightblue"
no <- "white"
現在您可以按如下方式繪制集合:
# A
p scale_fill_manual(values = c(A = yes, B = no, A..B = yes))

# B
p scale_fill_manual(values = c(A = no, B = yes, A..B = yes))

# A U B
p scale_fill_manual(values = c(A = yes, B = yes, A..B = yes))

# A n B
p scale_fill_manual(values = c(A = no, B = no, A..B = yes))

# A' U B'
p scale_fill_manual(values = c(A = no, B = no, A..B = no))
theme(panel.background = element_rect(fill = yes))

# B'
p scale_fill_manual(values = c(A = yes, B = no, A..B = no))
theme(panel.background = element_rect(fill = yes))

# A'
p scale_fill_manual(values = c(A = no, B = yes, A..B = no))
theme(panel.background = element_rect(fill = yes))

希望您有足夠的資源來適當地為您想要的任何元素著色。
由reprex 包于 2022-06-17 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/493115.html
上一篇:影片KaplanMeier圖,如何在x軸方向擴展繪圖區域
下一篇:設定mixfitEM圖的軸限制
