如何使某些区域的某些区域的颜色为颜色,其余的空白?

发布于 2025-02-08 08:05:37 字数 730 浏览 2 评论 0原文

例如,制作a∩b红色和其他所有白色。我已经附上了当前代码和Venn图的图像。

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))

For example, make A ∩ B red and everything else white. I've attached an image of my current code and Venn diagram.

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))

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离线来电— 2025-02-15 08:05:37

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))

img src =“ https://i.sstatic.net/dduui.png

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

< img src =“ https://i.sstatic.net/52bht.png” alt

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

=“ https://i.sstatic.net/saock.png”

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

=“”> “”

希望您在这里有足够的时间为您想要适当的任何元素上色。

ggVennDiagram isn't designed explicitly to draw diagrams of set membership, but it can be made to do so. If you use the following set-up:

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)

Then you can easily specify the membership / non-membership areas like this: first, specify the colors that you want to indicate whether an area is within the set or not:

yes <- "lightblue"
no  <- "white"

Now you can draw the sets as follows:

# 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))

Hopefully you have enough here to color any element you want appropriately.

Created on 2022-06-17 by the reprex package (v2.0.1)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文