I am trying to create multiple venns diagram in one single pdf. The script below works fine, but I need to adjust it so the circle sizes are fixed and SET1 appears always the first on the left side. Is it possible to adjust it?
library(VennDiagram)
library(gridExtra)
# Function to create fixed-size Venn diagram with SET1 always on the left
create_fixed_size_venn_vd <- function(SET1_file, SET2_file, plot_title) {
# Read data
SET1 <- read.table(SET1_file, header = TRUE, stringsAsFactors = FALSE)
SET2 <- read.table(SET2_file, header = TRUE, stringsAsFactors = FALSE)
# Filter unwanted positions (same as previous logic)
unwanted_positions <- c(205,789,1256)
SET1 <- SET1[!SET1$POS %in% unwanted_positions,]
SET2 <- SET2[!SET2$POS %in% unwanted_positions,]
# Extract positions
set1 <- SET1$POS
set2 <- SET2$POS
# Create the Venn diagram with fixed circle sizes and SET1 on the left, SET2 on the right
venn_plot <- venn.diagram(
x = list(SET1 = set1, SET2 = set2),
category.names = c("SET1", "SET2"), # Set names for categories
filename = NULL, # Don't save directly
output = TRUE,
scaled = FALSE, # Do not scale circles based on the data size
col = "black", # Border color
fill = c("lightblue", "lightgreen"), # Circle colors
alpha = 0.5, # Transparency
label.col = "black", # Label color
cex = 1.5, # Label size
fontfamily = "Arial", # Font
fontface = "bold", # Font style
cat.col = c("blue", "green"), # Category color
cat.cex = 1.5, # Category label size
cat.fontface = "bold", # Category font style
cat.pos = c(180, 0), # Place SET1 at 180° (left), SET2 at 0° (right)
cat.dist = 0.05, # Distance of category labels from circles
rotation.degree = 0, # No rotation of circles
main = plot_title, # Title
main.cex = 1.5, # Title font size
euler.d = FALSE, # Do not use Euler diagram (it scales circles)
ext.pos = 0, # Extra space around the diagram
margin = 0.1 # Adjust margin around the Venn diagram
)
return(venn_plot)
}
# List of file pairs with SET1 and SET2 file paths
file_pairs <- list(
list(SET1_file = "/path/to/SET1_file1.txt", SET2_file = "/path/to/SET2_file1.txt", plot_title = "Venn 1"),
list(SET1_file = "/path/to/SET1_file2.txt", SET2_file = "/path/to/SET2_file2.txt", plot_title = "Venn 2"),
list(SET1_file = "/path/to/SET1_file3.txt", SET2_file = "/path/to/SET2_file3.txt", plot_title = "Venn 3"),
# Add more file pairs as needed
)
# Generate each Venn diagram and save to list
venn_plots <- lapply(file_pairs, function(file_pair) {
create_fixed_size_venn_vd(SET1_file = file_pair$SET1_file,
SET2_file = file_pair$SET2_file,
plot_title = file_pair$plot_title)
})
# Plot the Venn diagrams in a grid
grid.arrange(grobs = venn_plots, ncol = 2)