将字符列表适应到一个维恩图中?

huangapple go评论67阅读模式
英文:

Fit a list of characters into a Venn diagram?

问题

这是原始数据集链接:https://correlatesofwar.org/wp-content/uploads/state_year_formatv3.zip

我在尝试将元素适合到 Venn 图中的正确圆圈时遇到了问题。Venn 图显示了两个国际组织的成员国。

国家字符代码无论是在 label_sep = "," 旁边还是在 label_sep = "\n" 下面都不适合。我不确定如何使元素适合圆圈内。如果有人能指导我正确的方向,这将非常有帮助。问候!


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")

我已经尝试将元素排列在一起(label_sep = ",")和排列在下面(label_sep = "\n")。如果在蓝色部分内有三列,那么这种方法可能有效 - 我不知道如何处理这个问题。

英文:

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(&quot;haven&quot;)
install.packages(&quot;tidyverse&quot;)
install.packages(&quot;ggvenn&quot;)
install.packages(&quot;countrycode&quot;)

library(&quot;haven&quot;)
library(&quot;tidyverse&quot;)
library(&quot;ggvenn&quot;)
library(&quot;countrycode&quot;)

data &lt;- read_dta(&quot;state_year_format3.dta&quot;)
data$cntry &lt;- countrycode(data$ccode, origin = &#39;cown&#39;, destination =  &#39;iso3c&#39;)


dta &lt;- data %&gt;% filter(year == 1975) %&gt;% 
                select(year, cmea, gatt,cntry)


# create a country list for GATT and CMEA 
GATT &lt;- dta %&gt;% filter(gatt == 1 )
CMEA &lt;- dta %&gt;% filter(cmea == 1)
x &lt;- list(GATT = GATT$cntry, CMEA = CMEA$cntry)

# venn diagram
ggvenn(x, show_elements = T, label_sep = &quot;\n&quot;)




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.

答案1

得分: 1

根据您的要求,以下是内容的翻译部分:

"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)"

"正如在评论中所解释的,我认为使用 ggvenn 来实现您想要的功能可能会比较困难,一般情况下,此函数似乎更多用于数字或百分比(请参见此处)。"

"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."

"然而,我进行了更多的研究,我认为您应该使用 venndir 函数来实现您想要的功能。您可以在此处的Github页面了解该函数的工作原理,以及此处如何安装和使用 venndir 包,还有Render Venn or Euler diagram可能也会引起您的兴趣。"

"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:"

"我在这里提供了一些代码和绘图示例,但您可以根据您的喜好进行修改,借助我之前分享的链接来帮助您:"

接下来是代码部分,不进行翻译。

英文:

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 &lt;- read.csv(&quot;state_year_formatv3.csv&quot;)
data$cntry &lt;- countrycode(data$ccode, origin = &#39;cown&#39;, destination =  &#39;iso3c&#39;)

dta &lt;- data %&gt;% filter(year == 1975) %&gt;% 
  select(year, CMEA, GATT,cntry)

# create a country list for GATT and CMEA 
GATT &lt;- dta %&gt;% filter(GATT == 1 )
CMEA &lt;- dta %&gt;% filter(CMEA == 1)
x &lt;- list(GATT = GATT$cntry, CMEA = CMEA$cntry)

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

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

将字符列表适应到一个维恩图中?
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 将字符列表适应到一个维恩图中?

huangapple
  • 本文由 发表于 2023年2月23日 22:37:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546278.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定