Reputation: 397
I'm having trouble widening the x axis of the forestplot. i.e. area inside the red box. I want to increase/zoom-in the plotted area(area inside the red box) without skipping any numbers. I want it to be wide enough for improved visibility. Any tips on how to expand the mean (95% CI) number lines would be greatly appreciated.
Can anyone help me?
Here are the r codes that I have used to create the above forestplot:
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)))
Upvotes: 0
Views: 1296
Reputation: 2059
Here is a potential solution to your problem. You can create the range of your x-axis
by doing this Tthis is just an example. I am not sure what values you want to use).
ticks <- c(0.04, 0.2, 1, 2)
attr(ticks, "labels") <- as.character(ticks)
You can add the ticks into your code to change the x-axis like this
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)))
Upvotes: 1