0
votes

I intend to put four graphs in a single page. Each plot shows the point estimate of a single statistic and its confidence interval. I am struggling with altering the width of geom_errorbar whisker in each plot. It does not seem to change, even though I alter the width argument in geom_errorbar().

It is important for me to graph those four statistics separately because both point estimates and confidence intervals are defined in different ranges for each statistic, as you can notice on the graph below. The multiplot function I use to plot multiple graphs is defined in http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/.

#creates data.frame where point estimates and confidence intervals will be 
#stored
#the numbers inputed in df are similar to the ones I get from previously 
#performed regressions
w<-c(1:4)
x<-c(0.68,0.87,2.93,4.66)
y<-c(0.47,0.57,0.97,3.38)
z<-c(0.83,1.34,4.17,7.46)
df<-data.frame(w,x,y,z)

#plot each statistic
#(each row from df is a statistic: w for index, x for point estimate,
#y for ci lower bound and z for ci upper bound)

p1 <- ggplot(df[1,], aes(x = w, y = x)) +
      geom_point(size = 4) +
      geom_errorbar(aes(ymax = y, ymin = z),width=.1) +
      labs(x="",y="")

p2 <- ggplot(df[2,], aes(x = w, y = x)) +
      geom_point(size = 4) +
      geom_errorbar(aes(ymax = y, ymin = z),width=.1) +
      labs(x="",y="")

p3 <- ggplot(df[3,], aes(x = w, y = x)) +
      geom_point(size = 4) +
      geom_errorbar(aes(ymax = y, ymin = z),width=.1) +
      labs(x="",y="")

p4 <- ggplot(df[4,], aes(x = w, y = x)) +
      geom_point(size = 4) +
      geom_errorbar(aes(ymax = y, ymin = z),width=.1) +
      labs(x="",y="")

multiplot(p1, p2, p3, p4, cols=2)

I greatly appreciate any help and advice.

Thanks, Gabriel

EXAMPLE PLOT HERE. How can I change errorbar whisker width for each graph separately?

1

1 Answers

0
votes

The width is changing, but the x-axis is scaling to match the width of the error bar. You need to set the x axis manually using, for example, xlim.

For p1, you could try + xlim(0.8, 1.2)

Alternatively you could use the expand argument to scale_x_continuous, e.g. scale_x_continuous(expand = c(0, 0.1)).