Reputation: 33
I am creating a forest plot with the forestplot() function.
The forest plot looks like this: Forest Plot
## Labels defining subgroups are a little indented!
subgps <- c(4,5,8,9,12,13,16,17,20,21,24,25,28,29,32,33)
data$Variable[subgps] <- paste(" ",data$Variable[subgps])
align = c("l", "l", "l", "l", "l", "l", "l", "l", "l", "l", "l")
library(forestplot)
png(file.path(workdir,"Figures\\Forestplot3.png"),width=1280, height=1000)
forestplot(labeltext=tabletext, graph.pos=3,
mean=c(NA,NA,data$Point.Estimate),
lower=c(NA,NA,data$Low), upper=c(NA,NA,data$High),
title="Hazard Ratio",
xlab="<---favors no ß-blockers--- ---favors ß-blockers--->", xlab.position="left",
hrzl_lines=list("3" = gpar(lwd=1, col="#99999922"),
"5" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
"14" = gpar(lwd=85, lineend="butt", columns=c(2:6), col="#99999922"),
"23" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
"31" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
"39" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
"47" = gpar(lwd=60, lineend="butt", columns=c(2:6), col="#99999922"),
"54" = gpar(lwd=27, lineend="butt", columns=c(2:6), col="#99999922")),
txt_gp=fpTxtGp(label=gpar(cex=1.25),
ticks=gpar(cex=1.1),
xlab=gpar(cex = 1.2),
title=gpar(cex = 1.2)),
col=fpColors(box="blue", lines="black", zero = "gray50"),
zero=1, cex=0.9, lineheight = "auto", boxsize=0.5, colgap=unit(6,"mm"),
lwd.ci=2, ci.vertices=TRUE, ci.vertices.height = 0.4)
x = .353
y0 = .08
y1 = .91
grid.lines(c(x, x), c(y0, y1), default.units = "npc",
gp = gpar(lwd = 1.7, col="#880000"))
dev.off()
I have two design problems:
In the upper pink bubble you can see that there is a problem with the text alignment. How can I change this?
In the lower pink bubble there is a problem with the grey background. It is defined by ""54" = gpar(lwd=27, lineend="butt", columns=c(2:6), col="#99999922")),", but if I choose line 53 or line 54 it does not work. So the grey background does not fit to the text.
Can anyone help? Thank you!
Upvotes: 2
Views: 758
Reputation: 5467
For alignment you should be able to use align
in the arguments. For the latter it is most likely just a case of your graph being too large, try just increasing the height to 1200 and see if that solves your issue. Your example was lacking the labeltext
and thus it is a little hard to test if this fixes your issues.
Upvotes: 1