0

venn Diagram

This is the original dataset: https://correlatesofwar.org/wp-content/uploads/state_year_formatv3.zip

I am having issues with fitting elements within a Venn diagram in the correct circle. The Venn diagram shows the country members of the two international organizations

The country character codes do not fit in either format - next to each other for label_sep = "," or underneath label_sep = "\n". I am unsure of how to make the elements fit in the circle otherwise.

If someone could point me in the rigth direction this would be very helpful. Greetings!


install.packages("haven")
install.packages("tidyverse")
install.packages("ggvenn")
install.packages("countrycode")

library("haven")
library("tidyverse")
library("ggvenn")
library("countrycode")

data <- read_dta("state_year_format3.dta")
data$cntry <- countrycode(data$ccode, origin = 'cown', destination =  'iso3c')


dta <- data %>% filter(year == 1975) %>% 
                select(year, cmea, gatt,cntry)


# create a country list for GATT and CMEA 
GATT <- dta %>% filter(gatt == 1 )
CMEA <- dta %>% filter(cmea == 1)
x <- list(GATT = GATT$cntry, CMEA = CMEA$cntry)

# venn diagram
ggvenn(x, show_elements = T, label_sep = "\n")




I have tried ordering the elements next to each other (label_sep = "," ) and underneath (label_sep = "\n"). If I had three columns within the bluish part, then this might work - no clue how to go about this.

Tribaldi
  • 177
  • 9
lisa
  • 3
  • 2
  • It's . asier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions.Exactly how many values are you trying to squeeze into that circle? – MrFlick Feb 23 '23 at 16:46
  • Thank you for your quick response! This is the dataset: https://correlatesofwar.org/wp-content/uploads/state_year_formatv3.zip – lisa Feb 24 '23 at 09:42
  • There are 81 elements (i.e. country codes) i would like to squeeze into the circle – lisa Feb 24 '23 at 09:43
  • Hello Lisa, I think it is difficult to use `ggvenn` for what you want to do, generally this function is rather used for number or percentage (e.g. [Beautiful GGPlot Venn Diagram with R](https://www.datanovia.com/en/blog/beautiful-ggplot-venn-diagram-with-r/)). I don't think you can add to the function to put your country names inside the circle. Except manually, but by doing that you won't have the common values between the two circles and you lose the `ggvenn` utility. Maybe you can looking for an other function, or do this manually. – Tribaldi Feb 27 '23 at 09:58

1 Answers1

0

As explained in the comment, I think it's difficult to use ggvenn for what you want to do, generally this function seems to be used more for a number or a percentage (see here)

However, I've done some more research and I think you should use the venndir function of the for what you want to do. You can see in the Github page here how the function works, here how to install and functioning of the package venndir and here the Render Venn or Euler diagram may also interest you.

I put here a code and examples of plots but you can modify according to your preferences with the help of the links I share with you just before:

data <- read.csv("state_year_formatv3.csv")
data$cntry <- countrycode(data$ccode, origin = 'cown', destination =  'iso3c')

dta <- data %>% filter(year == 1975) %>% 
  select(year, CMEA, GATT,cntry)

# create a country list for GATT and CMEA 
GATT <- dta %>% filter(GATT == 1 )
CMEA <- dta %>% filter(CMEA == 1)
x <- list(GATT = GATT$cntry, CMEA = CMEA$cntry)

# Venn diagram with venndir package
remotes::install_github("jmw86069/venndir")
install.packages("eulerr")
library(eulerr)
library(venndir)

par(mfrow=c(1, 2))
venndir(x,
        main="Non-proportional circles",
        #proportional=TRUE,
        overlap_type="overlap",
        #show_segments=FALSE,
        label_preset="main items",
        label_style="lite_box",
        show_items="item",
        item_cex=2)
venndir(x,
        main="Proportional circles",
        proportional=TRUE,
        overlap_type="overlap",
        #show_segments=FALSE,
        label_preset="main items",
        label_style="lite_box",
        show_items="item",
        item_cex=2)

enter image description here First example a plot with same size between circles, or in right, a plot with circle proportional of country numbers.

I hope to have answer to your question :)

Tribaldi
  • 177
  • 9