luccas_loki
luccas_loki

Reputation: 23

Create venn diagrams in R with circles one inside another

I want to create venn diagrams to emphasize that groups (circles) are completely located inside one another, i.e., there are no elements in the inner circles that are not simutanously in outer circles.

I've used ggvenn and arrived at these results:

colonias <- c("colônias")
possessoes <- c("possessões", colonias)
dominios <- c("domínios", possessoes, colonias)

ggvenn(tipologia_britanica,
       show_elements = T,
       label_sep = "\n",
       fill_color = brewer.pal(name="Dark2", n=3),
       fill_alpha = 0.6,
       stroke_size = 0.2,
       stroke_alpha = 0.2,
       set_name_size = 5,
       text_size = 5)

enter image description here

The result is tchnically correct because it show that "colonias" are common to all three groups and that "possessoes" are common to both "possessoes" and "dominios". But graphically I would like te groups to be completely inside one another to show that are no elements in "colonias" that are not common to all three, and in "possessoes" that are not common to "dominios". I'm not sure that ggvenn package is capable of plotting that.

EDIT:

I've tried the euller package and came up with a solution very close to what I wanted:

library(eulerr)

fit <- euler(c("domínios" = 1, "domínios&possessões" = 1, "domínios&possessões&colônias"=1))

plot(fit,
     fills = list(fill = c("red", "steelblue4","green"), alpha = 0.5),
     labels = list(col = "black", font = 4),quantities = T)

enter image description here

The only issue here is that eulerr seems to demand the insertion of numeric elements in the groups. This is a graphic representation of British oficial typology of its colonies, so I don't realy need element "1" in my groups, I just need to show that "colônias" is a sub-group of "possessões" which is a sub-group of "domínios". The actual elements in those groups are abstracted (they are the real historical British dominions, i.e., India, Canada, Kenya etc.).

I've tried inserting NA, character objects, and nothing at all to the groups, but then the code doesn't work.

Upvotes: 0

Views: 869

Answers (2)

Beeflight31
Beeflight31

Reputation: 249

One way may use the package eulerr. However, your question isn't very clear so I let you play with the package

See the example below :

library(eulerr)

fit <- euler(c("A" = 10, "B" = 10, "A&B" = 8, "A&B&C"=3))

plot(fit,
     fills = list(fill = c("red", "steelblue4","green"), alpha = 0.5),
     labels = list(col = "black", font = 4),quantities = T)

enter image description here

Upvotes: 2

Allan Cameron
Allan Cameron

Reputation: 173858

I don't think ggvenn allows a plot with this kind of relationship. However, it's not terribly difficult to draw it yourself with ggplot and geom_circle from ggforce

ggplot(data.frame(group = c("domínios", "possessões", "colônias"),
                  r = c(3, 2, 1)), 
       aes(x0 = 3 - r, y0 = 0, fill = factor(group, group))) +
  geom_circle(aes(r = r), alpha = 1) +
  geom_text(aes(x = c(0, 1, 2), y = c(2.3, 1.3, 0), label = group), 
            size = 8) +
  scale_fill_manual(values = c('#77bca2', '#e1926b', '#a09cc8'),
                    guide = 'none') +
  coord_equal() +
  theme_void() 

enter image description here

Upvotes: 1

Related Questions