如何在前图中使 X 轴变宽
How to make X axis wider in foresplot
我在加宽森林图的 x 轴时遇到问题。即红色框内的区域。我想 increase/zoom-in 绘制区域(红色框内的区域)而不跳过任何数字。
我希望它足够宽以提高可见度。任何关于如何扩展平均值 (95% CI) 数字行的提示都将不胜感激。
谁能帮帮我?
这是我用来创建上述森林图的 r 代码:
library(tidyverse)
library(ggplot2)
library(forestplot)
library(dplyr)
Number <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
group <- c('A','A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B','B')
labeltext <- c('Altered level of consciousness','Central neuropathy','Fever','Headache','Hypotension','Nausea vomiting','Pallor','Visual changes','Weakness','Altered level of consciousness','Central neuropathy','Fever',
'Headache','Hypotension','Nausea vomiting','Pallor','Visual changes','Weakness')
mean <- c(0.52,0.88,1.01,0.97,0.55 ,0.99,0.64,0.49,NA,NA,0.04 ,0.1,0.09,0.04,0.04,0.04 ,0.04,NA)
lower <-c(0.39,0.7,0.72,0.59,0.45,0.69,0.44,0.32,NA,NA,0.02,0.04,0.03,0.02,0.01,0.01,0.01,NA)
upper <-c(0.68,1.11,1.43,1.6,0.68,1.42,0.95,0.73,NA,NA,0.11,0.23,0.31,0.09,0.15,0.16,0.17,NA)
df <- data.frame(Number, group, labeltext, mean, lower, upper)
df <- df %>% mutate(est = sprintf("%.2f", mean), .after = labeltext)
clrs <- fpColors(box = "royalblue",line = "darkblue", summary = "royalblue")
tabletext <- list(c(NA, df %>% filter(group == "A") %>% pull(labeltext)),
append(list(expression(beta)), df %>% filter(group == "A") %>% pull(est)))
df %>%
filter(group == "A") %>%
bind_rows(tibble(mean = NA), .) %>%
forestplot(labeltext = tabletext,
col = clrs,
xlab = "95 CI")
df %>%
group_by(group) %>%
forestplot(title= "test header",
clip = c(0, 5),
lty.ci=c(2,3),
lwd.ci = 1,
shapes_gp = fpShapesGp(box = c("chocolate1", "aquamarine3") %>% lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)),
ci.vertices = TRUE,
ci.vertices.height = 0.05,
boxsize = .1,
ticks = gpar(fontfamily = "", cex = 5),
xlab = "mean (95% CI)",
grid=structure(c(1), gp=gpar(lty=2, lwd=1)))
这是您的问题的潜在解决方案。您可以通过执行此操作来创建 x-axis
的范围 Tthis 只是一个示例。我不确定你想使用什么值)。
ticks <- c(0.04, 0.2, 1, 2)
attr(ticks, "labels") <- as.character(ticks)
您可以将刻度添加到您的代码中以像这样更改 x 轴
df %>%
group_by(group) %>%
forestplot(title= "test header",
clip = c(0, 5),
lty.ci=c(2,3),
lwd.ci = 1,
shapes_gp = fpShapesGp(box = c("chocolate1", "aquamarine3") %>% lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)),
ci.vertices = TRUE,
ci.vertices.height = 0.05,
xticks=ticks, # ADDITION
boxsize = .1,
ticks = gpar(fontfamily = "", cex = 5),
xlab = "mean (95% CI)",
grid=structure(c(1), gp=gpar(lty=2, lwd=1)))
我在加宽森林图的 x 轴时遇到问题。即红色框内的区域。我想 increase/zoom-in 绘制区域(红色框内的区域)而不跳过任何数字。 我希望它足够宽以提高可见度。任何关于如何扩展平均值 (95% CI) 数字行的提示都将不胜感激。
谁能帮帮我?
这是我用来创建上述森林图的 r 代码:
library(tidyverse)
library(ggplot2)
library(forestplot)
library(dplyr)
Number <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18)
group <- c('A','A','A','A','A','A','A','A','A','B','B','B','B','B','B','B','B','B')
labeltext <- c('Altered level of consciousness','Central neuropathy','Fever','Headache','Hypotension','Nausea vomiting','Pallor','Visual changes','Weakness','Altered level of consciousness','Central neuropathy','Fever',
'Headache','Hypotension','Nausea vomiting','Pallor','Visual changes','Weakness')
mean <- c(0.52,0.88,1.01,0.97,0.55 ,0.99,0.64,0.49,NA,NA,0.04 ,0.1,0.09,0.04,0.04,0.04 ,0.04,NA)
lower <-c(0.39,0.7,0.72,0.59,0.45,0.69,0.44,0.32,NA,NA,0.02,0.04,0.03,0.02,0.01,0.01,0.01,NA)
upper <-c(0.68,1.11,1.43,1.6,0.68,1.42,0.95,0.73,NA,NA,0.11,0.23,0.31,0.09,0.15,0.16,0.17,NA)
df <- data.frame(Number, group, labeltext, mean, lower, upper)
df <- df %>% mutate(est = sprintf("%.2f", mean), .after = labeltext)
clrs <- fpColors(box = "royalblue",line = "darkblue", summary = "royalblue")
tabletext <- list(c(NA, df %>% filter(group == "A") %>% pull(labeltext)),
append(list(expression(beta)), df %>% filter(group == "A") %>% pull(est)))
df %>%
filter(group == "A") %>%
bind_rows(tibble(mean = NA), .) %>%
forestplot(labeltext = tabletext,
col = clrs,
xlab = "95 CI")
df %>%
group_by(group) %>%
forestplot(title= "test header",
clip = c(0, 5),
lty.ci=c(2,3),
lwd.ci = 1,
shapes_gp = fpShapesGp(box = c("chocolate1", "aquamarine3") %>% lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)),
ci.vertices = TRUE,
ci.vertices.height = 0.05,
boxsize = .1,
ticks = gpar(fontfamily = "", cex = 5),
xlab = "mean (95% CI)",
grid=structure(c(1), gp=gpar(lty=2, lwd=1)))
这是您的问题的潜在解决方案。您可以通过执行此操作来创建 x-axis
的范围 Tthis 只是一个示例。我不确定你想使用什么值)。
ticks <- c(0.04, 0.2, 1, 2)
attr(ticks, "labels") <- as.character(ticks)
您可以将刻度添加到您的代码中以像这样更改 x 轴
df %>%
group_by(group) %>%
forestplot(title= "test header",
clip = c(0, 5),
lty.ci=c(2,3),
lwd.ci = 1,
shapes_gp = fpShapesGp(box = c("chocolate1", "aquamarine3") %>% lapply(function(x) gpar(fill = x, col = "#555555")),
default = gpar(vertices = TRUE)),
ci.vertices = TRUE,
ci.vertices.height = 0.05,
xticks=ticks, # ADDITION
boxsize = .1,
ticks = gpar(fontfamily = "", cex = 5),
xlab = "mean (95% CI)",
grid=structure(c(1), gp=gpar(lty=2, lwd=1)))