1

我准备了一个代码来可视化我的数据:

    library(forestplot)
test_data <- data.frame(coef=c(1.14, 0.31, 10.70),
                        low=c(1.01, 0.12, 1.14),
                        high=c(1.30, 0.83, 100.16),
                        boxsize=c(0.2, 0.2, 0.2))
row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and nasty name of the variable"),
                   c("OR", test_data$coef), c("CI -95%",  test_data$low), c("CI +95%", test_data$high) )
test_data <- rbind(rep(NA, 4), test_data)
forestplot(labeltext = row_names,
           mean = test_data$coef, upper = test_data$high,
           lower = test_data$low,
           is.summary=c(TRUE, FALSE, FALSE, FALSE),
           boxsize = test_data$boxsize,
           zero = 1,
           xlog = TRUE,
           xlab = "OR (95% CI)",
           col = fpColors(lines="black", box="black"),
           title="My Happy Happy Title \n o happy happy title...\n",
           ci.vertices = TRUE,
           xticks = c(0.1, 1, 10, 100))

它给出了以下森林图:

森林图

我想:

1)扩大情节并缩小左侧情节细节的字体以获得更好的可视化

2)编辑“So looooooong and nasty name of the variable”将部分“name...”移动到行下方,如:“So looooooong and nasty name of the variable”但是,当我写为“/nSo.../ n”它给出了来自“OR”和“CIs”列的另一行数字。

怎么纠正?

4

1 回答 1

4

三种可能性(比您要求的多一种):

1) 用 更改行标签的文本txt_gp

colgap2) 通过将网格调用传递给单元,将列间距从 6 毫米默认值减少到该值的一半。充分了解选项forestplot需要了解grid绘图系统。

3)添加一个"\n"到loooong标签。(我很困惑您没有看到这种可能性,因为您的标题中已经有一个“\n”。)

row_names <- cbind(c("Variable", "Variable 1", "Variable 2", "So looooooong and \nnasty name of the variable"),
               c("OR", test_data$coef), c("CI -95%",  test_data$low), c("CI +95%", test_data$high) )

forestplot(labeltext = row_names,
           mean = test_data$coef, upper = test_data$high,
           lower = test_data$low,
           is.summary=c(TRUE, FALSE, FALSE, FALSE),
           boxsize = test_data$boxsize,
           zero = 1, colgap = unit(3, "mm"), txt_gp=fpTxtGp(label= gpar(cex = 0.7),
                                                             title = gpar(cex = 1) ),
           xlog = TRUE,
           xlab = "OR (95% CI)",
           col = fpColors(lines="black", box="black"),
           title="My Happy Happy Title \n o happy happy title...\n",
           ci.vertices = TRUE,
           xticks = c(0.1, 1, 10, 100))

在此处输入图像描述

如果我在传递给'label'的调用中只使用了0.7的cex gpar,它也会影响标题的大小,所以我需要将'title'的'cex'“重置”回1。

于 2018-12-30T18:16:18.047 回答