Reputation: 3470
I'm preparing e a forest plot in R through the forestplot package. The possible values range from -1 to +1, and I would like that to be the range on my x axis. My values, however, range from 0 to 1, so R is depicting only that part on the x axis.
See the image here:
How can I make the x axis interval range from -1 to +1? I want to leave a complete empty space on the right to show no value is there.
Here's my code:
library("forestplot")
cochrane_from_rmeta <-
structure(list(
lower = c(NA, NA, 0.026, 0.043, 0.184, 0.333, 0.026),
mean = c(NA, NA, 0.502, 0.534, 0.548, 0.792, 0.600),
upper = c(NA, NA, 0.978, 0.949, 0.911, 0.936, 0.967)),
.Names = c("mean", "lower", "upper"),
row.names = c(NA, -7L),
class = "data.frame")
tabletext<-cbind(
c("", "aaa", "bbb", "ccc",
"ddd", "eee",
"Summary"),
c("", "#datasets", "1", "2",
"3", "4",
NA))
png(paste0("forestPlot_",exe_num,".png"))
forestplot(tabletext,
cochrane_from_rmeta,
new_page = TRUE,
is.summary=c(TRUE,TRUE,rep(FALSE,4),TRUE),
clip=c(-1,1),
xlog=FALSE,
col=fpColors(box="royalblue",line="darkblue", summary="royalblue"))
Upvotes: 1
Views: 1063
Reputation: 173928
There doesn't seem to be a direct way of doing this, but if you set a lower and upper of -1 and 1 in your first row while leaving mean
as NA
, it will fix the x range without affecting the plot otherwise:
cochrane_from_rmeta <-
structure(list(
lower = c(-1, NA, 0.043, 0.043, 0.184, 0.333, 0.026),
mean = c(NA, NA, 0.502, 0.534, 0.548, 0.792, 0.600),
upper = c(1, NA, 0.978, 0.949, 0.911, 0.936, 0.967)),
.Names = c("mean", "lower", "upper"),
row.names = c(NA, -7L),
class = "data.frame")
tabletext<-cbind(
c("", "aaa", "bbb", "ccc",
"ddd", "eee",
"Summary"),
c("", "#datasets", "1", "2",
"3", "4",
NA))
forestplot(tabletext,
cochrane_from_rmeta,
new_page = TRUE,
is.summary=c(FALSE,TRUE,rep(FALSE,4),TRUE),
clip=c(-1,1),
xlog=FALSE,
mar = unit(c(50, 30, -30, 30), "pt"),
col=fpColors(box="royalblue",line="darkblue", summary="royalblue"),
graphwidth = unit(0.7, "npc"))
Upvotes: 2