我正在使用"皮条客你的森林情节"做一些漂亮的图表。 http://www.r-bloggers.com/pimping-your-forest-plot/
该教程解释了如何制作一个漂亮的森林图,梳理来自两个国家的数据以查看子组效果。每个国家在图表上都有自己独特的形状,例如瑞典是一颗钻石......因此,各国的小组效应很容易被挑选出来。
我尝试合并三个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
制作两个国家的森林地块:使用引用网站上的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")))
答案 0 :(得分:1)
很难在方形结构中推断出不同绘图函数的意图,因此需要为函数提供方形矩阵,在本例中为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)
生成此图表: