自行编写五组数据,调整颜色和外观,用r语言绘制韦恩图
时间: 2023-06-25 20:02:15 浏览: 162
好的,下面是五组数据:
```
set1 <- list(a = c("apple", "banana", "orange", "pear"),
b = c("apple", "orange", "peach", "watermelon"))
set2 <- list(a = c("cat", "dog", "rabbit", "hamster"),
b = c("dog", "hamster", "parrot"))
set3 <- list(a = c("red", "green", "blue"),
b = c("green", "purple", "blue"))
set4 <- list(a = c("math", "science", "history", "english"),
b = c("science", "english"))
set5 <- list(a = c("rain", "sunshine", "clouds", "snow"),
b = c("sunshine", "clouds"))
library(VennDiagram)
# 绘制韦恩图
venn.diagram(list(set1, set2, set3, set4, set5),
fill = c("#F8766D", "#00BFC4"),
alpha = 0.7,
filename = "venn.png",
imagetype = "png",
output=T,
main = "五组数据的韦恩图")
# 颜色调整
venn.plot <- draw.pairwise.venn(
area1 = 10,
area2 = 20,
cross.area = 5,
category = c("Group 1", "Group 2"),
fill = c("red", "blue"),
lty = "blank",
cex = 2,
cat.cex = 1.5,
cat.fontface = "bold",
cat.col = c("red", "blue")
)
# 外观调整
venn.plot <- draw.pairwise.venn(
area1 = 10,
area2 = 20,
cross.area = 5,
category = c("Group 1", "Group 2"),
fill = c("red", "blue"),
lwd = c(3, 3),
cex = 2,
cat.cex = 1.5,
cat.fontface = "bold",
cat.col = c("red", "blue"),
cat.dist = c(0.05, 0.05),
cat.pos = c(-30, 30)
)
# 保存为图片
png("venn.png", width = 800, height = 600)
grid.draw(venn.plot)
dev.off()
```
这个代码会生成一个名为 `venn.png` 的韦恩图,其中包含五组数据的交集情况。你可以根据自己的需求调整颜色和外观来使图形更加美观。
阅读全文