我准备了一个代码来可视化我的数据:
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 name name of the variable“以移动部分"name...”下面的行类似于:“So looooooong and nSo name of the variable”,然而,当我写为"/nSo.../n“时,它给出了"OR”和"CIs“列中的另一行数字。
怎么纠正呢?
发布于 2018-12-31 02:16:18
三种可能性(比你要求的多一种):
1)用txt_gp修改行标签的文本。
2)通过向单元传递colgap网格调用,将列间距从默认值6 mm减少到该值的一半。完全了解forestplot的选项需要了解grid打印系统。
3)在loooong标签中添加"\n"。(我很奇怪你没有看到这种可能性,因为你的标题中已经有了"\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‘的gpar时仅使用了0.7的cex,它也会影响标题的大小,所以我需要将' title’的'cex‘“重置”回1。
https://stackoverflow.com/questions/53979701
复制相似问题