title: Modifying axis scales on random effects plots using lme4 and ggCaterpillar in R with ggplot2
body: <p>I was wondering if someone could help me with something. I have a mixed effects model fitted with lme4 and I have extracted the random effects to plot in a dotplot. I have followed the very helpful code pasted below and have got the plot shown. However, I would like to be able to tidy up the x-axis scales a bit to make it look a bit tidier. Ideally I want axis tick labels at -0.1, 0.1 and 0.3. I have tried modifying the function with scale_x_continous in various places but as I am not entirely sure how the whole code works together I don't quite know where this would go or if this would even work. I would be very grateful for any assitance, thank you.</p>
  
  <pre><code>## re = object of class ranef.mer
  ggCaterpillar &lt;- function(re, QQ=TRUE, likeDotplot=TRUE) {
  require(ggplot2)
  f &lt;- function(x) {
  pv   &lt;- attr(x, "postVar")
  cols &lt;- 1:(dim(pv)[1])
  se   &lt;- unlist(lapply(cols, function(i) sqrt(pv[i, i, ])))
  ord  &lt;- unlist(lapply(x, order)) + rep((0:(ncol(x) - 1)) * nrow(x), each=nrow(x))
  pDf  &lt;- data.frame(y=unlist(x)[ord],
                     ci=1.96*se[ord],
                     nQQ=rep(qnorm(ppoints(nrow(x))), ncol(x)),
                     ID=factor(rep(rownames(x), ncol(x))[ord], levels=rownames(x)[ord]),
                     ind=gl(ncol(x), nrow(x), labels=names(x)))
  
  if(QQ) {  ## normal QQ-plot
    p &lt;- ggplot(pDf, aes(nQQ, y)) + scale_x_continous(limits=c(-0.6,0.7), breaks=seq(-0.6,0.7, by=0.1), labels=c("-0.6","-0.5","-0.4","0.3","0.2","0.1","0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7"))
    p &lt;- p + facet_wrap(~ ind, scales="free")
    p &lt;- p + xlab("Standard normal quantiles") + ylab("Random effect quantiles")
  } else {  ## caterpillar dotplot
    p &lt;- ggplot(pDf, aes(ID, y)) + coord_flip()
    if(likeDotplot) {  ## imitate dotplot() -&gt; same scales for random effects
      p &lt;- p + facet_wrap(~ ind)
    } else {           ## different scales for random effects
      p &lt;- p + facet_grid(ind ~ ., scales="free_y")
    }
    p &lt;- p + xlab("Levels") + ylab("Random effects")
  }
  
  p &lt;- p + theme(legend.position="none")
  p &lt;- p + geom_hline(yintercept=0)
  p &lt;- p + geom_errorbar(aes(ymin=y-ci, ymax=y+ci), width=0, colour="black")
  p &lt;- p + geom_point(aes(size=1.2), colour="blue") 
  return(p)
  #plotting the dotplot of my model
  ggCaterpillar(ranef(model, condVar=TRUE), QQ=FALSE)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/tMG2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tMG2E.png" alt="My dotplot"></a></p>