0

我正在使用“pimp your forest plot”来制作一些漂亮的图表。http://www.r-bloggers.com/pimping-your-forest-plot/

本教程解释了如何制作一个漂亮的森林图,结合来自两个国家的数据来查看子组效应。每个国家在图表上都有自己独特的形状,例如瑞典是一颗菱形……所以国家的子群效应很容易被挑选出来。

我在尝试合并三个 dfs(三个国家)时遇到了问题。不是为每个子组中的每个国家保留单独的形状(结合两个国家时请参见图表),当我将三个国家放在一起时,所有的性别形状都是圆形的,所有的年龄形状都是方形的,依此类推。相反,应该有一个圆圈、一个菱形和一个正方形来代表每个国家/地区的性别/年龄的影响。

有谁知道我在这里做错了什么?我一直在回溯我的步骤,一次添加一个 df,这样我至少可以尝试看看我做错了什么:但它不会来找我。

我在这里从“pimp your forest plot”中复制了一些 dfs:这些图表的所有功劳都归功于 Max Gordon。为了这里的一个例子,我制作了一个名为“finland”的假的第三个df。

sweden1
             coef       lower       upper
    Males vs Female          0.04088551  0.03483956  0.04693145
    85 vs 65 years          -0.05515741 -0.06508088 -0.04523394
    Charlsons Medium vs Low -0.03833060 -0.04727946 -0.02938173

denmark1
                               coef        lower       upper
Males vs Female          0.03462842  0.003494374 0.065762462
85 vs 65 years          -0.03682791 -0.083367305 0.009711488
Charlsons Medium vs Low -0.04335537 -0.090336663 0.003625929

 finland1
                          coef  lower  upper
Males vs Female          0.061  0.043  0.087
85 vs 65 years          -0.080 -0.120 -0.020
Charlsons Medium vs Low -0.050 -0.075 -0.025

要制作两个国家的森林图:使用参考网站上的 Max Gordon 代码:

library(forestplot)
forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"]), 
            lower=cbind(sweden1[,"lower"], denmark1[,"lower"]), 
            upper=cbind(sweden1[,"upper"], denmark1[,"upper"]), 
            labeltext=rownames(Sweden),
            legend=c("Sweden", "Denmark"), 
            legend.pos=list(x=0.8,y=.4),
            legend.gp = gpar(col="#AAAAAA"), 
            legend.r=unit(.1, "snpc"),
            clip=c(-.2, .2), 
            xticks=c(-.2, -.1, .0, .1, .2),
            boxsize=0.3,
            col=fpColors(box=c("blue", "darkred")),
            # Set the different functions
            confintNormalFn=c("fpDrawDiamondCI", "fpDrawCircleCI"),
            xlab="EQ-5D index",
            new_page=TRUE)

我使用这段代码在芬兰添加,但看看这些形状如何不忠于他们的群体。

forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"],finland1[,"coef"]), 
            lower=cbind(sweden1[,"lower"], denmark1[,"lower"],finland1[,"lower"]), 
            upper=cbind(sweden1[,"upper"], denmark1[,"upper"],finland1[,"upper"]), 
            labeltext=rownames(sweden1),
            legend=c("Sweden", "Denmark", "finland1"), 
            # Added the clip argument as some of 
            # the Danish CI are way out therer
            #clip=c(-.2, .2), 
            # Getting the ticks auto-generate is 
            # a nightmare - it is usually better to 
            # specify them on your own
           # xticks=c(-.2, -.1, .0, .1, .2),
            boxsize=0.3,
            col=fpColors(box=c("blue", "darkred", "green")),
           confintNormalFn=c("fpDrawCircleCI",  "fpDrawNormalCI","fpDrawDiamondCI"),
            xlab="EQ-5D index",
            new_page=TRUE)

提前致谢。

编辑

sweden1 <- structure(c(0.0408855062954068, -0.0551574080806885, -0.0383305964199184, 
0.0348395599810297, -0.0650808763059716, -0.0472794647337126, 
0.046931452609784, -0.0452339398554054, -0.0293817281061242), .Dim = c(3L, 
3L), .Dimnames = list(c("Males vs Female", "85 vs 65 years", 
"Charlsons Medium vs Low"), c("coef", "lower", "upper")))

denmark1 <- structure(c(0.0346284183072541, -0.0368279085760325, -0.0433553672510346, 
0.00349437418972517, -0.0833673052667752, -0.0903366633240568, 
0.065762462424783, 0.00971148811471034, 0.00362592882198759), .Dim = c(3L, 
3L), .Dimnames = list(c("Males vs Female", "85 vs 65 years", 
"Charlsons Medium vs Low"), c("coef", "lower", "upper")))

finland1 <- structure(c(0.061, -0.08, -0.05, 0.043, -0.12, -0.075, 0.087, 
-0.02, -0.025), .Dim = c(3L, 3L), .Dimnames = list(c("Males vs Female", 
"85 vs 65 years", "Charlsons Medium vs Low"), c("coef", "lower", 
"upper")))
4

1 回答 1

2

很难推断方形结构中不同绘图函数的意图,因此您需要为函数提供一个方阵,在本例中为 3x3 矩阵。不确定这是我最明智的设计选择,但修复起来相当简单:

sweden1 <- 
  structure(c(0.0408855062954068, -0.0551574080806885, -0.0383305964199184, 
              0.0348395599810297, -0.0650808763059716, -0.0472794647337126, 
              0.046931452609784, -0.0452339398554054, -0.0293817281061242), 
            .Dim = c(3L, 3L), 
            .Dimnames = list(c("Males vs Female", "85 vs 65 years", "Charlsons Medium vs Low"),
                             c("coef", "lower", "upper")))

denmark1 <- structure(c(0.0346284183072541, -0.0368279085760325, -0.0433553672510346, 
                        0.00349437418972517, -0.0833673052667752, -0.0903366633240568, 
                        0.065762462424783, 0.00971148811471034, 0.00362592882198759), 
                      .Dim = c(3L, 3L), 
                      .Dimnames = list(c("Males vs Female", "85 vs 65 years", "Charlsons Medium vs Low"),
                                       c("coef", "lower", "upper")))

finland1 <- structure(c(0.061, -0.08, -0.05, 
                        0.043, -0.12, -0.075, 
                        0.087, -0.02, -0.025),
                      .Dim = c(3L, 3L), 
                      .Dimnames = list(c("Males vs Female", "85 vs 65 years", "Charlsons Medium vs Low"),
                                       c("coef", "lower", "upper")))

forestplot(mean=cbind(sweden1[,"coef"], denmark1[,"coef"],finland1[,"coef"]), 
           lower=cbind(sweden1[,"lower"], denmark1[,"lower"],finland1[,"lower"]), 
           upper=cbind(sweden1[,"upper"], denmark1[,"upper"],finland1[,"upper"]), 
           labeltext=rownames(sweden1),
           legend=c("Sweden", "Denmark", "finland1"), 
           boxsize=0.1,
           col=fpColors(box=c("kblue", "darkred", "darkgreen")),
           fn.ci_norm=matrix(c("fpDrawCircleCI",  "fpDrawNormalCI","fpDrawDiamondCI"), 
                             nrow = 3, ncol=3, byrow=T),
           xlab="EQ-5D index",
           new_page=TRUE)

生成此图:

在此处输入图像描述

于 2015-07-14T18:42:32.723 回答