0

我正在forestplot使用forestplotR 中的包创建一个,并且遇到了一些问题。

问题:

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

输出:

在此处输入图像描述

期望:

我希望将两个5 year survival %文本位组合为 1(并在上面的两个标题之间居中),并且只是这些元素或整行为斜体字体。

我已经尝试使用summary=list(gpar(...))txt_gp选项,但这似乎只能修改整个列,而且我根本没有发现合并单元格。

4

1 回答 1

1

如果您使in比平时colgap小得多,您可以将当前在第 2 行第 3 列和第 4 列中重复的文本拆分为两部分:forestplot

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

在此处输入图像描述

于 2019-05-29T23:48:13.607 回答