2015-06-19 52 views
0

我使用“皮条客你的森林情节”来制作一些漂亮的图表。 http://www.r-bloggers.com/pimping-your-forest-plot/森林情节R中的三个形状

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

虽然尝试合并三个dfs(对于三个国家),但我遇到问题。与其为每个小组中的每个国家保留不同的形状(当组合两个国家时参见图表),当我将三个国家放在一起时,所有性别的形状都是圆形的,所有年龄的形状都是正方形等等。相反,它应该是有一个圆圈,一颗钻石和一个正方形来代表每个国家的性别/年龄的影响。

有没有人知道我在做什么错在这里?我一直在追踪我的步骤,并一次添加一个df,这样我至少可以试着看看我做错了什么,但这不是我想要的。

我已经从“皮条客你的森林情节”中复制了一些dfs:这些图表的所有功劳都归Max Gordon所有。为了这里的一个例子,我做了一个假的第三个df叫做“finland”。

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 

为了使森林图有两个国家:用最大戈登的代码从引用的网站:

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) 

在此先感谢。

EDIT

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"))) 
+0

请分享在[重现的格式]您的数据( http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)。现在将数据导入到R中并不容易,所以帮助你更加困难。查看'dput()'选项的数据。 – MrFlick

+0

道歉 - 以为我的dfs本来可以读入。感谢您的支持。 – user2363642

回答

1

很难推断的不同绘图功能的意图在方形的结构,因此需要提供的功能的方矩阵,在这种情况下3×3矩阵。不知道这是从我的部分是最明智的设计选择,但比较简单的解决:

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) 

产生以下图表:

enter image description here

+0

你是一个传奇人物。谢谢! – user2363642