将林图格式的元素合并为单个元素

时间:2019-05-24 01:28:24

标签: r forestplot

我正在使用R中的forestplot包创建一个forestplot,但遇到了一些麻烦。

问题:

  1. 是否可以合并两个相邻的文本元素
  2. 是否可以修改单个文本元素字体或整个行的字体

我的代码:

library(forestplot)

# creating text
text <- rbind(c('', 'N (%)', 'SRT', 'ART',  'HR [95% CI]'),
              c('', '', '5 year survival %',  '5 year survival %', ''),
              c('Seminal Vesicle Involvement', '', '', '', ''),
              c('        Yes', '10 (20%)',   '94', '12', '0.73  [0.36, 1.50]'),
              c('        No', '40 (80%)',   '96', '10', '1.78  [0.73, 4.35]'),
              c('Gender', '', '', '', ''),
              c('        Male', '13 (22.5%)', '84', '22', '0.06  [-0.2, 0.86]'),
              c('        Female', '37 (77.5%)', '93', '13', '1.89  [0.90, 6.67]'))

# creating the plot
forestplot(text, 
           mean = c(NA, NA, NA, 0.73, 1.78, NA, 0.06, 1.89), 
           lower = c(NA, NA, NA, 0.36, 0.73, NA, -0.2, 0.90), 
           upper = c(NA, NA, NA, 1.50, 4.35, NA, 0.86, 6.67),
           is.summary=c(T, T, T, F, F, T, F, F),
           lineheight = unit(0.9, "cm"),
           graph.pos = 5,
           graphwidth = unit(4, 'cm'),
           xticks = c(-1, 0, 1, 2, 3, 4),
           ci.vertices = T,
           txt_gp = fpTxtGp(ticks = gpar(cex = 1),
                            xlab  = gpar(cex = 1),
                            label = gpar(cex = 0.8),
                            summary = gpar(cex = 0.8)),
           col=fpColors(box="black", 
                        line="darkgrey", 
                        summary="black", 
                        zero='grey20', 
                        axes='grey20'),
           hrzl_lines = list("2" = gpar(lwd=1, col = "#000044")))

输出:

enter image description here

所需:

我希望将两个5 year survival %文本位合并为1(并居中于上述两个标题之间),或者将那些元素或整行都合并为斜体。

我尝试对summary=list(gpar(...))选项使用txt_gp,但这似乎只能修改整个列,而且在合并单元格方面我什么也没发现。

1 个答案:

答案 0 :(得分:1)

如果您使colgap中的forestplot比平常小得多,则可以将当前在第3行和第4列的第2行中复制的文本分成两部分:

> text[2, 4] <- 'survival % '
> text[2, 3] <- '5 year '
> 
> forestplot(text, 
+            mean = c(NA, NA, NA, 0.73, 1.78, NA, 0.06, 1.89), 
+            lower = c(NA, NA, NA, 0.36, 0.73, NA, -0.2, 0.90), 
+            upper = c(NA, NA, NA, 1.50, 4.35, NA, 0.86, 6.67),
+            is.summary=c(T, T, T, F, F, T, F, F),
+            lineheight = unit(0.9, "cm"),
+            graph.pos = 5,
+            graphwidth = unit(4, 'cm'),
+            xticks = c(-1, 0, 1, 2, 3, 4),
+            ci.vertices = T, 
#   add line---------
          colgap=unit(.0011,"npc"),
#
+            txt_gp = fpTxtGp(ticks = gpar(cex = 1),
+                             xlab  = gpar(cex = 1),
+                             label = gpar(cex = 0.8),
+                             summary = gpar(cex = 0.8)),
+            col=fpColors(box="black", 
+                         line="darkgrey", 
+                         summary="black", 
+                         zero='grey20', 
+                         axes='grey20'),
+            hrzl_lines = list("2" = gpar(lwd=1, col = "#000044")))

enter image description here