森林图 R 中的三种形状
forest plot three shapes in R
我正在使用 "pimp your forest plot" 制作一些漂亮的图表。 http://www.r-bloggers.com/pimping-your-forest-plot/
本教程解释了如何制作漂亮的森林图,结合来自两个国家的数据以查看子组效应。每个国家在图表上都有自己独特的形状,例如瑞典是一个菱形......因此国家的子组效应很容易挑选出来。
不过,我在尝试合并三个 df(针对三个国家/地区)时遇到了问题。当我将三个国家放在一起时,不是为每个子组中的每个国家/地区保留单独的形状(参见图表合并两个国家/地区),然后所有性别的形状都是圆形的,所有年龄的形状都是方形的等等。而是应该有一个圆圈,一个菱形和一个正方形来代表每个国家gender/age的效果。
有谁知道我在这里做错了什么?我一直在追溯我的步骤并一次添加一个 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")))
很难推断出方形结构中不同绘图函数的意图,因此您需要为该函数提供一个方阵,在本例中为 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)
生成此图:
我正在使用 "pimp your forest plot" 制作一些漂亮的图表。 http://www.r-bloggers.com/pimping-your-forest-plot/
本教程解释了如何制作漂亮的森林图,结合来自两个国家的数据以查看子组效应。每个国家在图表上都有自己独特的形状,例如瑞典是一个菱形......因此国家的子组效应很容易挑选出来。
不过,我在尝试合并三个 df(针对三个国家/地区)时遇到了问题。当我将三个国家放在一起时,不是为每个子组中的每个国家/地区保留单独的形状(参见图表合并两个国家/地区),然后所有性别的形状都是圆形的,所有年龄的形状都是方形的等等。而是应该有一个圆圈,一个菱形和一个正方形来代表每个国家gender/age的效果。
有谁知道我在这里做错了什么?我一直在追溯我的步骤并一次添加一个 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")))
很难推断出方形结构中不同绘图函数的意图,因此您需要为该函数提供一个方阵,在本例中为 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)
生成此图: