gpt4 book ai didi

r - 使用 VennDiagram 在 RStudio 查看器中查看 venn.diagram(不仅仅是写入文件)?

转载 作者:行者123 更新时间:2023-12-02 09:03:20 28 4
gpt4 key购买 nike

使用 VennDiagram包,我们可以用 venn.diagram() 制作像这样的维恩图功能 like so :

enter image description here

library(tidyverse)
library(hrbrthemes)
library(tm)
library(proustr)

# Load dataset from github
data <- read.table("https://raw.githubusercontent.com/holtzy/data_to_viz/master/Example_dataset/14_SeveralIndepLists.csv", header=TRUE)
to_remove <- c("_|[0-9]|\\.|function|^id|script|var|div|null|typeof|opts|if|^r$|undefined|false|loaded|true|settimeout|eval|else|artist")
data <- data %>% filter(!grepl(to_remove, word)) %>% filter(!word %in% stopwords('fr')) %>% filter(!word %in% proust_stopwords()$word)

# library
library(VennDiagram)

#Make the plot
venn.diagram(
x = list(
data %>% filter(artist=="booba") %>% select(word) %>% unlist() ,
data %>% filter(artist=="nekfeu") %>% select(word) %>% unlist() ,
data %>% filter(artist=="georges-brassens") %>% select(word) %>% unlist()
),
category.names = c("Booba (1995)" , "Nekfeu (663)" , "Brassens (471)"),
filename = 'venn.png',
output = TRUE ,
imagetype="png" ,
height = 480 ,
width = 480 ,
resolution = 300,
compression = "lzw",
lwd = 1,
col=c("#440154ff", '#21908dff', '#fde725ff'),
fill = c(alpha("#440154ff",0.3), alpha('#21908dff',0.3), alpha('#fde725ff',0.3)),
cex = 0.5,
fontfamily = "sans",
cat.cex = 0.3,
cat.default.pos = "outer",
cat.pos = c(-27, 27, 135),
cat.dist = c(0.055, 0.055, 0.085),
cat.fontfamily = "sans",
cat.col = c("#440154ff", '#21908dff', '#fde725ff'),
rotation = 1
)


这会导致 .png直接写到工作中。

如何在 RStudio 查看器 Pane 中查看它,并在 RMarkdown 文档等中使用它(即,就像查看常规 ggplot 或基本图一样)?

另请注意,相同的问题适用于 ?
venn.diagram
中的任何示例。文档(它们似乎都写入文件而不是在 RStudio 查看器中显示)

最佳答案

这也应该完成这项工作。我删除了可读性的参数:

...
plt <- venn.diagram(
filename = NULL,
cex = 1,
cat.cex = 1,
lwd = 2,
)
grid::grid.draw(plt)

来自 ?venn.diagram

filename
Filename for image output, or if NULL returns the grid object itself



看起来,你几乎可以控制任何事情。再次文档:

... A series of graphical parameters tweaking the plot. See below for details Details

Argument Venn Sizes Class Description
cex 1,2,3,4,5 numeric Vector giving the size for each area label (length = 1/3/7/15 based on set-number)



因此我们需要能够显示 grid对象。 plot()print()不要做这个工作(似乎没有 print.grid() )。

关于r - 使用 VennDiagram 在 RStudio 查看器中查看 venn.diagram(不仅仅是写入文件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61391220/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com