我正在使用 ggplot2 在 R 中创建维恩图。 但是,我想将集合名称的标签(“OST 上的 ID”和“ITT 上的 IR”)从圆圈的顶部移动到圆圈的两侧或底部。 我尝试使用位置来调整位置,但它改变了整个维恩图。 任何帮助将不胜感激。
#libraries
library(ggplot2)
library(dplyr)
#Create dataset
name <- c(1:18)
itt <- c("FALSE","TRUE","FALSE","TRUE","FALSE","TRUE","TRUE","FALSE","FALSE","FALSE","TRUE","FALSE","TRUE","TRUE","FALSE","FALSE","FALSE","TRUE")
ost <- c("FALSE","TRUE","FALSE","TRUE","FALSE","FALSE","FALSE","TRUE","TRUE","TRUE","TRUE","FALSE","TRUE","TRUE","TRUE","TRUE","TRUE","TRUE")
M <- tibble(name,itt,ost)
M <- M %>% mutate_at(c("itt","ost"),as.logical)
#Use ggplot to create Venn Diagram
ggplot(M,aes(A=ost, B=itt))+
geom_venn(set_name_size = 4, auto_scale=TRUE,set_names=c("ID on OST","IR on ITT"),fill_color = c("firebrick","darkgray"),fill_alpha = 0.65,show_percentage = FALSE,show_outside="none")+
ggtitle("Placebo Group")+
coord_fixed()+
theme_void()+theme(plot.title = element_text(hjust=0.5,vjust=-5))
在许多旨在使创建某些绘图类型变得更容易的 ggplot 扩展中,您在易用性中获得的东西,在易用性定制中会失去。这对于“ggvenn”包来说似乎是正确的:从阅读文档来看,似乎没有移动文本标签的选项,也不能使它们的字体/大小/颜色与数字标签不同。我们能做的最好的事情就是通过传递空字符串来删除它们,然后使用
ggplot2
函数 annotate
随意绘制我们自己的标签:
ggplot(M, aes(A = ost, B = itt)) +
geom_venn(set_name_size = 4,
auto_scale = TRUE,
set_names = c("", ""),
fill_color = c("firebrick", "darkgray"),
fill_alpha = 0.65,
show_percentage = FALSE,
show_outside = "none",
text_size = 12) +
ggtitle("Placebo Group") +
lims(x = c(-1.4, 1.1), y = c(-1.3, 1.1)) +
annotate("text", label = c("ID on OST", "IR on ITT"), x = c(-1, 0.8),
y = c(-1.1, -0.8), size = 12) +
coord_fixed() +
theme_void(30) +
theme(plot.title = element_text(hjust = 0.5))