【发布时间】:2021-02-09 14:07:38
【问题描述】:
我整天都在努力创建一个流程图来代表我们纳入研究的一些患者。
我已经在 Power Point 演示文稿中准备了一个粗略的版本,描述了我正在寻找什么样的安排。
现在,我已经准备好所有的盒子,但我需要的是与附图中的箭头相同的对齐方式和连接方式。我试图在此页面上复制和粘贴指南https://cran.r-project.org/web/packages/Gmisc/vignettes/Grid-based_flowcharts.html,但现在我被卡住了。由于我没有使用 R 的专业知识,并且只是偶尔使用它,因此您可能会看到一些简单的东西,而我没有。
这是我的代码:
install.packages("Gmisc")
library(Gmisc, quietly = TRUE)
library(glue)
library(htmlTable)
library(grid)
library(magrittr)
org_cohort <- boxGrob(glue("Patients with pancreatic cancer admitted to the University Clinic of Essen",
"from 01/2002 to 08/2020",
"n = {pop}",
pop = txtInt(909),
.sep = "\n"))
included <- boxGrob(glue("Patients with genetic sequencing and survival data",
"n = {incl}",
incl = txtInt(412),
.sep = "\n"))
grp_a <- boxGrob(glue("Patients treated with FOLFIRINOX or Gemcitabine / nab-Paclitaxel",
"n = {recr}",
recr = txtInt(179),
.sep = "\n"))
grp_b <- boxGrob(glue("Patients with genetic sequencing data via MAPK-TRON panel",
"n = {recr}",
recr = txtInt(185),
.sep = "\n"))
excluded_1 <- boxGrob(glue("Excluded (n = {tot}):",
" - No survival data: {NoSurv}",
" - No MAPK-Tron panel and early available abdominal CT-scan: {NoMAPKCT}",
tot = 506,
NoSurv = 300,
NoMAPKCT = 206,
.sep = "\n"),
just = "left")
excluded_2 <- boxGrob(glue("Excluded (n = {NoFGP}):",
" - No FOLFIRINOX or Gemcitabine / nab-Paclitaxel as 1st line: {NoFGP}",
NoFGP = 233,
.sep = "\n"),
just = "left")
excluded_3 <- boxGrob(glue("Excluded (n = {NoMAPK}):",
" - No sequencing data available: {NoMAPK}",
NoMAPK = 227,
.sep = "\n"),
just = "left")
grid.newpage()
vert <- spreadVertical(org_cohort = org_cohort,
included = included,
grps = grp_a)
grps <- alignVertical(reference = vert$grp_a,
grp_a, grp_b) %>%
spreadHorizontal()
vert$grps <- NULL
excluded_1 <- moveBox(excluded_1,
x = .8,
y = coords(vert$included)$top + distance(vert$included, vert$org_cohort, half = TRUE, center = FALSE))
excluded_2 <- moveBox(excluded_2,
x = .8,
y = coords(vert$grp_a)$top + distance(vert$included, vert$grp_a, half = TRUE, center = FALSE))
excluded_3 <- moveBox(excluded_3,
x = .8,
y = coords(vert$grp_b)$bottom + distance(vert$included, vert$grp_b, half = TRUE, center = FALSE))
## already facing problems here: R gives me the following error message: Error in coords(vert$grp_a/b) :
#Assertion on 'box' failed: Must inherit from class 'box', but has class 'NULL'..
for (i in 1:(length(vert) - 1)) {
connectGrob(vert[[i]], vert[[i + 1]], type = "vert") %>%
print
}
connectGrob(vert$included, grps[[1]], type = "N")
connectGrob(vert$included, grps[[2]], type = "N")
connectGrob(vert$included, excluded_1, type = "L")
connectGrob(vert$grp_a, excluded_2, type = "L")
# Print boxes
vert
grps
excluded_1
excluded_2
excluded_3
老实说:在“grid.newpage()”之后,我并没有真正得到代码。因此,我一直在尝试了解代码组件的实际作用,但每次我认为我理解了它的工作原理时,另一个挫折就在拐角处等着我。 R 基本上给了我一个到处都是箭头和框的情节,但不是我希望它们看起来的样子。那么有时我的盒子太大了还是什么?特别是图表末尾的两个子组的框经常被截断...
你知道如何“强制”R 为我复制那种图表(见图)吗?
非常感谢您的帮助,让我离最终完成我的论文更近一步......!
提前谢谢你!!
【问题讨论】:
-
我也可以考虑使用
DiagrammeR包来做这样的事情:datascienceplus.com/… -
@Ben 谢谢,这看起来肯定更容易......我稍后会试试这个!
-
好吧,所以 DiagrammeR 似乎没有将一个盒子与其他两个盒子同时垂直和水平连接的功能......也许我错过了一些东西,但我没有找到任何线索关于如何使用这个包。