r - 如何使用 R 中的元包更改森林图中子组的顺序?

标签 r

我需要一些帮助来更改子组在我的森林图中的显示顺序。我正在使用 R 中的 meta 包来执行元分析并生成我的森林图。我在下面提供了一些示例数据。

mydata <- data.frame(
  A = 1:9,
  Ms = sample(100:500, 9),
  Ss = sample(10:50, 9),
  Mr = sample(100:500, 9),
  Sr = sample(10:50, 9),
  Ns = sample(5:50, 9),
  Nr = sample(5:50, 9),
  P = sample(c("foot", "tibia", "lumbar"), 9, replace = TRUE)
  )

这是一些用于运行我的荟萃分析的基本代码。

ma <- metacont(Ns,
               Ms,
               Ss,
               Nr,
               Mr,
               Sr,
               data = mydata,
               byvar = P,
               comb.fixed = FALSE,
               comb.random = TRUE)

我使用 byvar 函数来运行子组分析。这是我用来绘制结果的代码。

forest(ma,
       layout = "RevMan5",
       subgroup = TRUE,
       print.byvar = FALSE)

我希望将子组排序为脚、胫骨和腰椎,而不是脚、腰椎和胫骨(如下面的链接所示)。我不知道如何做到这一点,任何帮助将不胜感激。

enter image description here

最佳答案

在最新版本的meta包中,您应该在原始数据集中设置P的因子水平。

考虑这个原始版本:

set.seed(123)
mydata <- data.frame(A = 1:9,  Ms = sample(100:500, 9), Ss = sample(10:50, 9),  Mr = sample(100:500, 9),
                     Sr = sample(10:50, 9),  Ns = sample(5:50, 9),  Nr = sample(5:50, 9),
                     P = sample(c("foot", "tibia", "lumbar"), 9, replace = TRUE))

ma <- metacont(Ns, Ms, Ss, Nr, Mr, Sr, data = mydata, byvar = P, comb.fixed = FALSE, comb.random = TRUE)

enter image description here

现在更改 P 的因子水平:

mydata$P <- factor(mydata$P, levels = c("foot", "tibia", "lumbar"))

ma <- metacont(Ns, Ms, Ss, Nr, Mr, Sr, data = mydata, byvar = P, comb.fixed = FALSE, comb.random = TRUE)
forest(ma, layout = "RevMan5", subgroup = TRUE, print.byvar = FALSE, bysort = FALSE)

enter image description here

在以前的版本中,您可以更改元对象对象的 $bylevs 元素。

ma$bylevs <- c("foot", "tibia", "lumbar")
forest(ma,
       layout = "RevMan5",
       subgroup = TRUE,
       print.byvar = FALSE)

关于r - 如何使用 R 中的元包更改森林图中子组的顺序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63025925/

相关文章:

r - 必须加速逐行操作

r - R 中 pairwise.t.test 的数据操作

r - 在 R 中可视化强连接组件

r - 在 R 中分割字符串时有效替换 for 循环

r - 具有 all.equal() 功能的 unique() 或 duplicated() ?

r - 使用 dplyr 过滤 R 中的因子级别

r - Amazon Elastic MapReduce 上的 R 映射器脚本故障排除 - 结果不符合预期

r - 带 ggplot2 的核型图和 SNP(geom_path、geom_bar、ggbio)

r - 如何在大量的 VennDiagram 中放置逗号?

r - 使用字符串作为 ipwtm 函数的公式?