I am creating a Venn diagram in R using ggplot2. However, I would like to move the labels for the set names ("ID on OST" and "IR on ITT") from the top of the circles to either the sides or bottom of the circles. I tried using position to adjust the location but it shifted the entire Venn diagram. Any help would be greatly appreciated.
#libraries
library(ggplot2)
library(dplyr)
library(ggvenn)
#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))
In many ggplot extensions that aim to make it easier to create certain plot types, what you gain in ease-of-use, you lose in ease-of-customization. This appears to be true of the "ggvenn" package: from reading over the documents, there seem to be no options to move the text labels, nor can you make them different in font / size / color from the numeric labels. The best we can do is remove them by passing empty strings, then using the ggplot2
function annotate
to draw our own labels as we please:
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))