在 R 中的森林图的标题中将两列组合成一行
Combine two columns in one row in the title of a forestplot in R
我有一个森林图,我正在尝试将两列组合成一个标题。
我的数据库是这样的:
> text.TI[1:10,]
Names Present Absent OR
[1,] "" "" "" ""
[2,] "Drug" "Drug Present" "Drug Absent" "aOR (95%CI)"
[3,] "" "" "" ""
[4,] "" "" "" ""
[5,] "N03AG" "3/5 (60.0%)" "179/973 (18.4%)" "60.52 (6.02 - 608.82)"
[6,] "A10AB" "6/8 (75.0%)" "176/970 (18.1%)" "14.40 (2.16 - 95.89)"
[7,] "J01EA" "12/24 (50.0%)" "170/954 (17.8%)" "8.43 (3.23 - 22.00)"
[8,] "A07AA" "3/5 (60.0%)" "179/973 (18.4%)" "7.22 (1.01 - 51.74)"
[9,] "B01AB" "6/12 (50.0%)" "176/966 (18.2%)" "5.61 (1.45 - 21.71)"
[10,] "B03XA" "5/9 (55.6%)" "177/969 (18.3%)" "5.37 (1.18 - 24.47)"
> m.TI[1:10]
[1] NA NA NA NA 4.103040 2.667506 2.131678 1.977270 1.725263 1.681573
> l.TI[1:10]
[1] NA NA NA NA 1.79458880 0.77195836 1.17248214 0.00796817 0.37225297 0.16636154
> u.TI[1:10]
[1] NA NA NA NA 6.411518 4.563254 3.090952 3.946173 3.077957 3.197284
当我用这段代码做我的森林图时:
tiff('HR1.tiff', units="in", width=10, height=20, res=300)
forestplot(text.TI,m.TI,l.TI,u.TI,xlog=T,zero=0,
is.summary=c(T,T,T,T,rep(F,87)),
col = meta.colors(lines="black",zero="black"), align=c('l','c'),clip=c(log(0.1),log(20)),boxsize=c(rep(0.4,91)),graphwidth=unit(4, "inches"))
x <- unit(.451, 'npc')
y <- unit(.15, 'npc')
x2 <- unit(.29, 'npc')
y2 <- unit(.11, 'npc')
xt <- unit(.5, 'npc')
yt <- unit(.84, 'npc')
我得到了我的林地
我的 objective 实际上是在两个单元格中包含两列的文本,我实际上是在完成我的森林图后用图像编辑器来完成的:
看到文本“died/total no.% 的患者人数”实际上在第 2 行和第 3 行中。
有没有办法直接在 R 中执行此操作并获取该图像作为我的 forestplot 函数的输出,而不使用图像编辑器?
我用函数 grid.text
解决了它
使用此代码:
grid.text("no. of patiens who died/total no. (%)", .5, .9, gp = gpar(fontsize=10, font = 3))
我有一个森林图,我正在尝试将两列组合成一个标题。
我的数据库是这样的:
> text.TI[1:10,]
Names Present Absent OR
[1,] "" "" "" ""
[2,] "Drug" "Drug Present" "Drug Absent" "aOR (95%CI)"
[3,] "" "" "" ""
[4,] "" "" "" ""
[5,] "N03AG" "3/5 (60.0%)" "179/973 (18.4%)" "60.52 (6.02 - 608.82)"
[6,] "A10AB" "6/8 (75.0%)" "176/970 (18.1%)" "14.40 (2.16 - 95.89)"
[7,] "J01EA" "12/24 (50.0%)" "170/954 (17.8%)" "8.43 (3.23 - 22.00)"
[8,] "A07AA" "3/5 (60.0%)" "179/973 (18.4%)" "7.22 (1.01 - 51.74)"
[9,] "B01AB" "6/12 (50.0%)" "176/966 (18.2%)" "5.61 (1.45 - 21.71)"
[10,] "B03XA" "5/9 (55.6%)" "177/969 (18.3%)" "5.37 (1.18 - 24.47)"
> m.TI[1:10]
[1] NA NA NA NA 4.103040 2.667506 2.131678 1.977270 1.725263 1.681573
> l.TI[1:10]
[1] NA NA NA NA 1.79458880 0.77195836 1.17248214 0.00796817 0.37225297 0.16636154
> u.TI[1:10]
[1] NA NA NA NA 6.411518 4.563254 3.090952 3.946173 3.077957 3.197284
当我用这段代码做我的森林图时:
tiff('HR1.tiff', units="in", width=10, height=20, res=300)
forestplot(text.TI,m.TI,l.TI,u.TI,xlog=T,zero=0,
is.summary=c(T,T,T,T,rep(F,87)),
col = meta.colors(lines="black",zero="black"), align=c('l','c'),clip=c(log(0.1),log(20)),boxsize=c(rep(0.4,91)),graphwidth=unit(4, "inches"))
x <- unit(.451, 'npc')
y <- unit(.15, 'npc')
x2 <- unit(.29, 'npc')
y2 <- unit(.11, 'npc')
xt <- unit(.5, 'npc')
yt <- unit(.84, 'npc')
我得到了我的林地
我的 objective 实际上是在两个单元格中包含两列的文本,我实际上是在完成我的森林图后用图像编辑器来完成的:
看到文本“died/total no.% 的患者人数”实际上在第 2 行和第 3 行中。
有没有办法直接在 R 中执行此操作并获取该图像作为我的 forestplot 函数的输出,而不使用图像编辑器?
我用函数 grid.text
使用此代码:
grid.text("no. of patiens who died/total no. (%)", .5, .9, gp = gpar(fontsize=10, font = 3))