英文:
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")。如果在蓝色部分内有三列,那么这种方法可能有效 - 我不知道如何处理这个问题。
英文:
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.
答案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 <- 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)
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论