Skip to main content
edited tags
Source Link
stefan
  • 114.4k
  • 6
  • 34
  • 67

First time posting here... I have a Venn diagram where I have coded certain regions of intersections based on internally defined categories. I want to produce a legend that reflects those categories.

So far all I can find are Venn diagram legends that are populated based on the counts contained in the intersection regions. Although the counts are an important part of the Venn diagram, they are sufficiently represented in the figure with labels. Here's a coded example that produces a lengthy legend with each intersection listed (e.g., A, B, C, D, A..B, A..C, ...) to the right of the appropriately colored square, e.g., white, blue, or salmon. What I want is a succinct legend with just the three defined categories, one for each color with the text to the right specified as 'Exclude', 'Sample', and 'All'.

library(ggplot2)
library(ggVennDiagram)

x <- list(A = sample(1:50, 30), B = sample(10:60, 45), C = sample(1:100, 60), D = sample(1:50, 30))
v <- ggVennDiagram(x, label = 'count', label_alpha = 0) + 
  scale_color_manual(values = rep('black', 4))

v$layers[[1]]$mapping <- aes(fill = name)
Exclude <- 'white'
Sample <- 'skyblue'
All <- 'lightsalmon'
  
v + scale_fill_manual(values = c(A = Exclude, B = Exclude, C = Exclude, D = Exclude,
                                  A..B = Exclude, A..C = Sample, A..D = All,
                                  B..C = All, B..D = All, C..D = Exclude,
                                  A..B..C = Sample, A..B..D = Sample, A..C..D = All,
                                  B..C..D = All, A..B..C..D = Sample))

Venn diagram legend with each intersection specifiedVenn diagram legend with each intersection specified

First time posting here... I have a Venn diagram where I have coded certain regions of intersections based on internally defined categories. I want to produce a legend that reflects those categories.

So far all I can find are Venn diagram legends that are populated based on the counts contained in the intersection regions. Although the counts are an important part of the Venn diagram, they are sufficiently represented in the figure with labels. Here's a coded example that produces a lengthy legend with each intersection listed (e.g., A, B, C, D, A..B, A..C, ...) to the right of the appropriately colored square, e.g., white, blue, or salmon. What I want is a succinct legend with just the three defined categories, one for each color with the text to the right specified as 'Exclude', 'Sample', and 'All'.

library(ggplot2)
library(ggVennDiagram)

x <- list(A = sample(1:50, 30), B = sample(10:60, 45), C = sample(1:100, 60), D = sample(1:50, 30))
v <- ggVennDiagram(x, label = 'count', label_alpha = 0) + 
  scale_color_manual(values = rep('black', 4))

v$layers[[1]]$mapping <- aes(fill = name)
Exclude <- 'white'
Sample <- 'skyblue'
All <- 'lightsalmon'
  
v + scale_fill_manual(values = c(A = Exclude, B = Exclude, C = Exclude, D = Exclude,
                                  A..B = Exclude, A..C = Sample, A..D = All,
                                  B..C = All, B..D = All, C..D = Exclude,
                                  A..B..C = Sample, A..B..D = Sample, A..C..D = All,
                                  B..C..D = All, A..B..C..D = Sample))

Venn diagram legend with each intersection specified

First time posting here... I have a Venn diagram where I have coded certain regions of intersections based on internally defined categories. I want to produce a legend that reflects those categories.

So far all I can find are Venn diagram legends that are populated based on the counts contained in the intersection regions. Although the counts are an important part of the Venn diagram, they are sufficiently represented in the figure with labels. Here's a coded example that produces a lengthy legend with each intersection listed (e.g., A, B, C, D, A..B, A..C, ...) to the right of the appropriately colored square, e.g., white, blue, or salmon. What I want is a succinct legend with just the three defined categories, one for each color with the text to the right specified as 'Exclude', 'Sample', and 'All'.

library(ggplot2)
library(ggVennDiagram)

x <- list(A = sample(1:50, 30), B = sample(10:60, 45), C = sample(1:100, 60), D = sample(1:50, 30))
v <- ggVennDiagram(x, label = 'count', label_alpha = 0) + 
  scale_color_manual(values = rep('black', 4))

v$layers[[1]]$mapping <- aes(fill = name)
Exclude <- 'white'
Sample <- 'skyblue'
All <- 'lightsalmon'
  
v + scale_fill_manual(values = c(A = Exclude, B = Exclude, C = Exclude, D = Exclude,
                                  A..B = Exclude, A..C = Sample, A..D = All,
                                  B..C = All, B..D = All, C..D = Exclude,
                                  A..B..C = Sample, A..B..D = Sample, A..C..D = All,
                                  B..C..D = All, A..B..C..D = Sample))

Venn diagram legend with each intersection specified

Source Link

R Customize ggVennDigram legend based on internally defined categories of mapped colors - not counts nor individual intersections

First time posting here... I have a Venn diagram where I have coded certain regions of intersections based on internally defined categories. I want to produce a legend that reflects those categories.

So far all I can find are Venn diagram legends that are populated based on the counts contained in the intersection regions. Although the counts are an important part of the Venn diagram, they are sufficiently represented in the figure with labels. Here's a coded example that produces a lengthy legend with each intersection listed (e.g., A, B, C, D, A..B, A..C, ...) to the right of the appropriately colored square, e.g., white, blue, or salmon. What I want is a succinct legend with just the three defined categories, one for each color with the text to the right specified as 'Exclude', 'Sample', and 'All'.

library(ggplot2)
library(ggVennDiagram)

x <- list(A = sample(1:50, 30), B = sample(10:60, 45), C = sample(1:100, 60), D = sample(1:50, 30))
v <- ggVennDiagram(x, label = 'count', label_alpha = 0) + 
  scale_color_manual(values = rep('black', 4))

v$layers[[1]]$mapping <- aes(fill = name)
Exclude <- 'white'
Sample <- 'skyblue'
All <- 'lightsalmon'
  
v + scale_fill_manual(values = c(A = Exclude, B = Exclude, C = Exclude, D = Exclude,
                                  A..B = Exclude, A..C = Sample, A..D = All,
                                  B..C = All, B..D = All, C..D = Exclude,
                                  A..B..C = Sample, A..B..D = Sample, A..C..D = All,
                                  B..C..D = All, A..B..C..D = Sample))

Venn diagram legend with each intersection specified