### Install ggVennDiagram from GitHub Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Install the development version of ggVennDiagram from GitHub. Ensure devtools is installed first. ```r # install.packages("devtools") devtools::install_github("gaospecial/ggVennDiagram") ``` -------------------------------- ### Install ggVennDiagram from CRAN Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Install the released version of ggVennDiagram from CRAN. ```r install.packages("ggVennDiagram") ``` -------------------------------- ### Basic Venn Diagram Example Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Generates a basic Venn diagram with 4 sets. The fill color of each region is mapped to its quantity. Requires the ggplot2 library for further customization. ```r library(ggVennDiagram) genes <- paste("gene",1:1000,sep="") set.seed(20231214) x <- list(A=sample(genes,300), B=sample(genes,525), C=sample(genes,440), D=sample(genes,350)) ``` ```r library(ggplot2) ggVennDiagram(x) + scale_fill_gradient(low="grey90",high = "red") ``` -------------------------------- ### Get and Use Specific Venn Diagram Shapes Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Demonstrates how to retrieve specific Venn diagram shapes by ID or type and use them in a ggVennDiagram plot. Requires the ggVennDiagram package. ```r shape_4set <- get_shape_data(nsets = 4) shape_polygon <- get_shape_data(nsets = 4, type = "polygon") fancy_ellipse <- get_shape_by_id("401f") plot_shape_edge(fancy_ellipse) gene_list <- list(A = 1:50, B = 25:75, C = 50:100, D = 75:125) ggVennDiagram(gene_list, shape_id = "401f") # Fancy ellipse shape ggVennDiagram(gene_list, shape_id = "402") # Alternative 4-set shape ``` -------------------------------- ### Adjust Upset Plot Appearance with Relative Dimensions Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Illustrates how to adjust the appearance of an upset plot by modifying the 'relative_height' and 'relative_width' parameters. This example specifically gives more space to the lower panel by setting 'relative_height' to 2. ```R venn = Venn(x) plot_upset(venn, nintersects = 30, relative_height = 2, relative_width = 0.3) ``` -------------------------------- ### Launch Shiny Application for Venn Diagrams Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Launches an interactive Shiny web application for creating Venn diagrams without writing code. This is useful for non-programmers or quick exploratory analysis. Requires the ggVennDiagram and shiny packages. ```r library(ggVennDiagram) # Launch the Shiny app (requires shiny package) launch_app() ``` -------------------------------- ### Venn() Constructor Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Creates a Venn S4 class object from a list of sets for data processing. ```APIDOC ## Venn(sets, names) ### Description Initializes a Venn object which serves as the foundation for set operations. ### Parameters #### Request Body - **sets** (list) - Required - A list of vectors. - **names** (vector) - Optional - Custom names for the sets. ``` -------------------------------- ### Use Different Label Formats in Venn Diagrams Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Illustrates various label display options for Venn diagrams: 'count' for only counts, 'percent' for only percentages, and 'none' to hide all labels. Ensure the 'label' argument is set accordingly. ```R # Use different label formats ggVennDiagram(gene_list, label = "count") # Only counts ggVennDiagram(gene_list, label = "percent") # Only percentages ggVennDiagram(gene_list, label = "none") # No labels ``` -------------------------------- ### Generate Venn Diagrams for 2 to 7 Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Demonstrates how to generate Venn diagrams for an increasing number of sets, from two up to seven, using the ggVennDiagram function. The 'label' argument is set to 'none' to hide set labels. ```R x <- list(A=sample(genes,300), B=sample(genes,525), C=sample(genes,440), D=sample(genes,350), E=sample(genes,200), F=sample(genes,150), G=sample(genes,100)) # two dimension Venn plot ggVennDiagram(x[1:2],label = "none") # three dimension Venn plot ggVennDiagram(x[1:3],label = "none") # four dimension Venn plot ggVennDiagram(x[1:4],label = "none") # five dimension Venn plot ggVennDiagram(x[1:5],label = "none") # six dimension Venn plot ggVennDiagram(x[1:6],label = "none") # seven dimension Venn plot ggVennDiagram(x,label = "none") ``` -------------------------------- ### Create 2-Set and 3-Set Venn Diagrams Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Demonstrates creating Venn diagrams for 2 and 3 sets by subsetting the gene list. The function automatically adjusts the visualization based on the number of sets provided. ```R # 2-set and 3-set diagrams ggVennDiagram(gene_list[1:2]) ggVennDiagram(gene_list[1:3]) ``` -------------------------------- ### Create Venn Diagram Data Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Prepare sample gene data for creating a Venn diagram. This involves creating a list of gene sets. ```r library(ggVennDiagram) genes <- paste("gene",1:1000,sep="") set.seed(20231214) x <- list(A=sample(genes,300), B=sample(genes,525), C=sample(genes,440), D=sample(genes,350)) ``` -------------------------------- ### Create Basic 4-Set Venn Diagram Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Generates a basic 4-set Venn diagram using sample gene lists. Ensure ggVennDiagram and ggplot2 libraries are loaded. ```R library(ggVennDiagram) library(ggplot2) # Create sample data - gene lists from different experimental conditions genes <- paste0("gene", 1:1000) set.seed(20231214) gene_list <- list( Treatment_A = sample(genes, 300), Treatment_B = sample(genes, 525), Control = sample(genes, 440), Knockout = sample(genes, 350) ) # Basic 4-set Venn diagram ggVennDiagram(gene_list) ``` -------------------------------- ### Force Upset Plot Generation Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Demonstrates how to force the generation of an upset plot for a specified number of sets (four in this case) by setting the 'force_upset' argument to TRUE. It also shows ordering sets by name and intersections by none. ```R ggVennDiagram(x[1:4], force_upset = TRUE, order.set.by = "name", order.intersect.by = "none") ``` -------------------------------- ### Manage Venn Shapes Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Explore available Venn diagram shapes using get_shapes(). ```r library(ggVennDiagram) # View all available shapes get_shapes() # Returns tibble with: shape_id, nsets, type # shape_id: "101", "201", "301", "401", "401f", "402", "501", ... # nsets: 2, 3, 4, 4, 4, 5, ... # type: "circle", "circle", "circle", "ellipse", "polygon", ... ``` -------------------------------- ### Create Venn Object with Custom Names Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Initializes a Venn object using custom names for the sets. If names are not provided, the function automatically assigns default names like 'Set_1', 'Set_2', etc. ```R # Create with custom names venn_custom <- Venn( sets = list(1:10, 5:15, 8:20), names = c("Group1", "Group2", "Group3") ) # Unnamed lists get automatic names venn_auto <- Venn(list(letters[1:5], letters[3:8])) # SetNames: Set_1, Set_2 ``` -------------------------------- ### Generate Multiple Venn Diagrams with Customization Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Generates a series of Venn diagrams for 2 to 7 sets, applying custom labels, edge sizes, color palettes, and theme settings. This snippet is useful for visualizing the progression of set intersections. ```R set.seed(20210507) x <- list(A = sample(genes,100), B = sample(genes,150), C = sample(genes,200), D = sample(genes,250), E = sample(genes,300), F = sample(genes,350), G = sample(genes,400)) plots <- lapply(2:7, function(i) ggVennDiagram(x[1:i],label = "none",edge_size = 0.5) + labs(title = paste("sets = ", i)) + scale_fill_distiller(palette = "RdBu") + theme(legend.position = "none", title = element_text(hjust = 0.5))) cowplot::plot_grid(plotlist = plots, ncol = 2) ``` -------------------------------- ### Interactive Venn Diagram with Show Intersect Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Enables interactive display of intersection values for Venn diagrams using `show_intersect = TRUE`. This feature requires the GitHub version and may be less useful with many items. ```r ggVennDiagram(y, show_intersect = TRUE) ``` -------------------------------- ### Create Venn Class Object Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Constructs a Venn S4 class object from a list of named sets. This object is the basis for subsequent set operations and data processing within the ggVennDiagram package. ```R library(ggVennDiagram) # Create a Venn object from named lists sample_sets <- list( A = c("apple", "banana", "cherry", "date"), B = c("banana", "cherry", "elderberry", "fig"), C = c("cherry", "date", "fig", "grape") ) venn <- Venn(sample_sets) print(venn) # Output: # An object of class 'Venn': # Slots: sets, names; # No. Sets: 3 SetNames: A, B, C. ``` -------------------------------- ### Venn Diagram with Custom Set Colors Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Creates a Venn diagram with custom colors for each set. The `set_color` argument accepts a vector of color names. ```r ggVennDiagram(x, set_color = c("blue","red","green","purple")) ``` -------------------------------- ### Venn Diagram for Five Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a five-dimensional Venn diagram. Set `label = "none"` to hide labels. ```r ggVennDiagram(x[1:5],label = "none") ``` -------------------------------- ### Process Data for Custom Plots Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Prepare Venn data for custom ggplot2 rendering using process_data() to obtain geometric and set information. ```r library(ggVennDiagram) library(ggplot2) gene_list <- list( A = sample(paste0("gene", 1:1000), 100), B = sample(paste0("gene", 1:1000), 200), C = sample(paste0("gene", 1:1000), 300), D = sample(paste0("gene", 1:1000), 200) ) venn <- Venn(gene_list) data <- process_data(venn) # Access different components venn_setedge(data) # Polygon coordinates for set boundaries venn_setlabel(data) # Set label positions and names venn_regionedge(data) # Region polygon coordinates with counts venn_regionlabel(data) # Region label positions with counts venn_set(data) # Set data with items and counts venn_region(data) # Region data with intersection items # Build fully custom Venn diagram ggplot() + geom_polygon(aes(X, Y, fill = count, group = id), data = venn_regionedge(data)) + geom_path(aes(X, Y, color = id, group = id), data = venn_setedge(data), linewidth = 2, show.legend = FALSE) + geom_text(aes(X, Y, label = name), fontface = "bold", data = venn_setlabel(data)) + geom_label(aes(X, Y, label = count), data = venn_regionlabel(data), alpha = 0.7) + scale_fill_viridis_c() + coord_equal() + theme_void() ``` -------------------------------- ### Enable Interactive Venn Diagrams with Plotly Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Enables interactive Venn diagrams using Plotly by setting `show_intersect = TRUE`. This allows users to hover over regions to see intersection members. Requires the ggVennDiagram and plotly packages. ```r library(ggVennDiagram) sample_data <- list( Group_A = c("apple", "banana", "cherry", "date", "elderberry"), Group_B = c("banana", "cherry", "fig", "grape", "honeydew"), Group_C = c("cherry", "date", "grape", "kiwi", "lemon"), Group_D = c("date", "fig", "kiwi", "mango", "nectarine") ) ggVennDiagram(sample_data, show_intersect = TRUE, set_color = "black", label_txtWidth = 30) gene_sample <- list( Condition1 = paste0("gene", sample(1:100, 20)), Condition2 = paste0("gene", sample(1:100, 25)), Condition3 = paste0("gene", sample(1:100, 18)) ) ggVennDiagram(gene_sample, show_intersect = TRUE) ``` -------------------------------- ### Generate Basic Venn Diagram Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generate a basic Venn diagram using the ggVennDiagram function. The fill color can be modified using ggplot2 functions. ```r library(ggplot2) ggVennDiagram(x) + scale_fill_gradient(low="grey90",high = "red") ``` -------------------------------- ### Set Operations Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Functions for calculating intersections, unions, and differences between sets. ```APIDOC ## overlap(venn, slice) ### Description Calculates the intersection of sets. - **slice** (vector) - Optional - Indices or names of sets to intersect. ## unite(venn, slice) ### Description Computes the union of sets. - **slice** (vector) - Optional - Indices or names of sets to unite. ## discern(venn, slice1, slice2) ### Description Calculates the set difference (elements in slice1 but not in slice2). - **slice1** (vector) - Required - Indices or names of the primary sets. - **slice2** (vector) - Optional - Indices or names of sets to exclude. ``` -------------------------------- ### Venn Diagram for Three Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a three-dimensional Venn diagram. Set `label = "none"` to hide labels. ```r ggVennDiagram(x[1:3],label = "none") ``` -------------------------------- ### Venn Diagram for Seven Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a seven-dimensional Venn diagram. Set `label = "none"` to hide labels. Note that Venn diagrams for more than four sets may be meaningless in some conditions. ```r ggVennDiagram(x,label = "none") ``` -------------------------------- ### ggVennDiagram() Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt The primary function for generating Venn diagram visualizations from a list of sets. ```APIDOC ## ggVennDiagram(x, category.names, set_color, label, label_alpha) ### Description Generates a Venn diagram visualization for 2-7 sets. Automatically switches to upset plot mode for more than 7 sets. ### Parameters #### Request Body - **x** (list) - Required - A list of vectors representing the sets. - **category.names** (vector) - Optional - Custom names for the sets. - **set_color** (vector) - Optional - Colors for set edges. - **label** (string) - Optional - Label format: 'both', 'count', 'percent', or 'none'. - **label_alpha** (numeric) - Optional - Transparency of the label background. ``` -------------------------------- ### Venn Diagram for Two Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a two-dimensional Venn diagram. Set `label = "none"` to hide labels. ```r ggVennDiagram(x[1:2],label = "none") ``` -------------------------------- ### Venn Diagram for Six Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a six-dimensional Venn diagram. Set `label = "none"` to hide labels. ```r ggVennDiagram(x[1:6],label = "none") ``` -------------------------------- ### Calculate Set Difference (Elements in Set 1, Not Set 2) Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Computes the set difference, returning elements present in the first group of sets but not in the second. Use `slice1` for the first group and `slice2` for the second group. ```R library(ggVennDiagram) venn <- Venn(list( A = letters[1:10], B = letters[3:12], C = letters[6:15] )) # Elements in set 1 but not in any other sets discern(venn, slice1 = 1) # Returns: "a" "b" # Elements in sets 1 and 2 but not in set 3 discern(venn, slice1 = c(1, 2), slice2 = 3) # Returns: "a" "b" "c" "d" "e" # Elements unique to set A (not in B or C) discern(venn, slice1 = "A") ``` -------------------------------- ### Venn Diagram for Four Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Generates a four-dimensional Venn diagram. Set `label = "none"` to hide labels. ```r ggVennDiagram(x[1:4],label = "none") ``` -------------------------------- ### Venn Diagram with Custom Category Names Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Assigns custom names to the sets in the Venn diagram using the `category.names` argument. ```r ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4")) ``` -------------------------------- ### Customize Venn Diagram Colors and Labels Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Customizes the appearance of a Venn diagram by setting category names, set colors, and label display options. Use 'label = "both"' to show counts and percentages, and 'label_alpha = 0' to remove label backgrounds. ```R ggVennDiagram(gene_list, category.names = c("Treat A", "Treat B", "Control", "KO"), set_color = c("blue", "red", "green", "purple"), label = "both", # Show count and percent label_alpha = 0) # Remove label background ``` -------------------------------- ### Generate Upset Plot via ggVennDiagram Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.md Automatically triggers an Upset plot when the input list exceeds the supported 2-7 dimension range for Venn diagrams. ```R x$H = sample(genes,500) ggVennDiagram(x) ``` -------------------------------- ### Generate Upset Plot for Unlimited Sets Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Automatically generates an upset plot when the number of sets exceeds seven. This is achieved by adding an extra member to the list and calling ggVennDiagram. ```R # add an extra member in list x$H = sample(genes,500) ggVennDiagram(x) ``` -------------------------------- ### Venn Diagram with Transparent Labels Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Removes the background from the region labels in the Venn diagram by setting `label_alpha = 0`. ```r ggVennDiagram(x, label_alpha=0) ``` -------------------------------- ### Venn Diagram without Labels Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Generates a Venn diagram where the labels for each region are hidden using `label = "none"`. ```r ggVennDiagram(x,category.names = c("Stage 1","Stage 2","Stage 3", "Stage4"), label = "none") ``` -------------------------------- ### Generate Upset Plots Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Visualize complex set intersections using plot_upset(), which is automatically triggered for more than 7 sets. ```r library(ggVennDiagram) # Create sample data with many sets set.seed(42) multi_sets <- list( A = sample(LETTERS, 20), B = sample(LETTERS, 22), C = sample(LETTERS, 14), D = sample(LETTERS, 18), E = sample(LETTERS, 16) ) venn <- Venn(multi_sets) # Basic upset plot plot_upset(venn) # Customize ordering and appearance plot_upset(venn, nintersects = 15, # Show top 15 intersections order.intersect.by = "size", # Order by intersection size order.set.by = "name", # Order sets alphabetically relative_height = 2.5, # Adjust panel heights relative_width = 0.4) # Adjust panel widths # Show numbers on set bars plot_upset(venn, sets.bar.show.numbers = TRUE, sets.bar.numbers.hjust = 1.2, top.bar.show.numbers = TRUE, top.bar.numbers.size = 4) # Force upset plot for small number of sets ggVennDiagram(multi_sets[1:4], force_upset = TRUE) # ggVennDiagram auto-switches to upset for >7 sets large_sets <- lapply(1:8, function(i) sample(LETTERS, sample(10:20, 1))) names(large_sets) <- paste0("Set", 1:8) ggVennDiagram(large_sets) # Automatically uses upset plot ``` -------------------------------- ### Customize Venn Diagram Fill Gradient Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Applies a custom fill gradient to a Venn diagram and positions the legend at the bottom. This allows for visual representation of intersection sizes or other quantitative data. ```R ggVennDiagram(gene_list) + scale_fill_gradient(low = "grey90", high = "red") + theme(legend.position = "bottom") ``` -------------------------------- ### Compute Union of All Sets Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Computes the union of all sets within a Venn object, returning all unique elements present across any of the sets. The `unite()` function aggregates elements from the specified sets. ```R library(ggVennDiagram) venn <- Venn(list( A = letters[1:10], # a-j B = letters[3:12], # c-l C = letters[6:15] # f-o )) # Union of all sets unite(venn) # Returns: all letters from a to o ``` -------------------------------- ### Process Venn Diagram Region Data Source: https://github.com/gaospecial/ggvenndiagram/blob/master/README.rmd Uses the `process_region_data()` function to extract intersection values from a Venn object. This requires the GitHub version of the package. ```r y <- list( A = sample(letters, 8), B = sample(letters, 8), C = sample(letters, 8), D = sample(letters, 8) ) process_region_data(Venn(y)) ``` -------------------------------- ### Compute Union of Specific Sets Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Calculates the union of specified sets within a Venn object, identified by index or name. This function returns all unique elements present in the selected sets. ```R # Union of specific sets unite(venn, slice = c(1, 2)) # Returns: "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" # Union by set names unite(venn, slice = c("A", "B")) ``` -------------------------------- ### Calculate Overlap of Specific Sets Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Calculates the intersection of specific sets within a Venn object, identified by their index or name. Use the `slice` argument to specify which sets to compare. ```R # Find intersection of specific sets by index overlap(venn, slice = c(1, 2)) # Returns: "c" "d" "e" "f" "g" "h" "i" "j" # Find intersection by set names overlap(venn, slice = c("A", "C")) # Returns: "f" "g" "h" "i" "j" ``` -------------------------------- ### Calculate Overlap of All Sets Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Computes the intersection of all sets within a Venn object. The `overlap()` function returns elements that are common to all specified sets. ```R library(ggVennDiagram) venn <- Venn(list( A = letters[1:10], # a-j B = letters[3:12], # c-l C = letters[6:15] # f-o )) # Find intersection of all sets overlap(venn) # Returns: "f" "g" "h" "i" "j" ``` -------------------------------- ### Extract Region Data Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Extract intersection details into a tibble using process_region_data(), which includes identifiers, names, items, and counts. ```r library(ggVennDiagram) y <- list( A = sample(letters, 8), B = sample(letters, 8), C = sample(letters, 8), D = sample(letters, 8) ) venn <- Venn(y) region_data <- process_region_data(venn) # View all 15 regions (2^4 - 1 for 4 sets) print(region_data) # Returns tibble with columns: id, name, item, count # id: "1", "2", "3", "4", "1/2", "1/3", "1/4", ... # name: "A", "B", "C", "D", "A/B", "A/C", "A/D", ... # item: list of items in each region # count: number of items in each region # Access items in specific intersections region_data$item[[which(region_data$name == "A/B/C")]] # Get items exclusive to all four sets region_data$item[[which(region_data$name == "A/B/C/D")]] ``` -------------------------------- ### Discern Set Overlaps Source: https://context7.com/gaospecial/ggvenndiagram/llms.txt Use discern_overlap() to find items exclusive to a specific intersection region, excluding items present in other sets. ```r library(ggVennDiagram) venn <- Venn(list( A = 1:5, B = 3:8, C = c(1L, 3L, 5L, 7L, 9L) )) # Items specific to the A&B intersection (not in C) discern_overlap(venn, slice = 1:2) # Returns: 4 (only item in A AND B but NOT in C) # Compare with regular overlap overlap(venn, slice = 1:2) # Returns: 3, 4, 5 (all items in A AND B, regardless of C) # Items exclusive to all three sets discern_overlap(venn, slice = "all") # Returns: 3, 5 (items in A AND B AND C) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.