title: ggplot2: Plotting two models with regression coefficients
body: <p>I would like to replicate the figure below with <code>ggplot2</code> (though larger, I don't know why the figure is so small here).</p>
  
  <p><a href="https://i.stack.imgur.com/8rng6.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8rng6.gif" alt="Original graph developed in Stata"></a></p>
  
  <p>(The subject of this research is the integration of Muslim minority youth.)</p>
  
  <p>I developed the original figure above with the package -coefplot- in Stata and now try to the same in R. </p>
  
  <p>In R and <code>ggplot2</code>, I start with two simple data frames obtained with <code>MplusAutomation</code> (from estimates in the Mplus application). The data frames can be reproduces with the following code:</p>
  
  <pre><code>resModel1 &lt;- 
    structure(list(param = c("FEMALE", "CHRISTIAN", "MUSLIM"), 
    low2.5 = c(-0.436, 0.038, 0.19), 
    est = c(-0.271, 0.18, 0.354), up2.5 = c(-0.106, 0.323, 0.519)), 
    .Names = c("param", "low2.5", "est", "up2.5"), row.names = 7:9, 
    class = c("data.frame", "mplus.params"))
  
  resModel2 &lt;- 
    structure(list(param = c("FEMALE", "CHRISTIAN", "MUSLIM", "CHRISTGI", "MUSLIMGI"), 
    low2.5 = c(-0.672, -0.256, -0.018, 0.131, -0.143), 
    est = c(-0.437, -0.038, 0.237, 0.403, 0.237), up2.5 = c(-0.203,                                                                                 0.18, 0.493, 0.675, 0.617)), .Names = c("param", "low2.5", "est", "up2.5"), 
    row.names = 7:11, class = c("data.frame", "mplus.params"))
  </code></pre>
  
  <p>I then try to develop two plots with <code>ggplot2</code> and to combine them with <code>gridExtra</code>: </p>
  
  <pre><code>library(ggplot2)
  limits &lt;- aes(ymax  = up2.5, ymin = low2.5) 
  
  plot1 &lt;- ggplot(resModel1, aes(x=param, y=est)) + 
    geom_pointrange(limits, color = "darkblue") + 
    scale_x_discrete("") + 
    geom_hline(yintercept=0, color="red") + 
    theme_bw() + 
    theme(text = element_text(size=10)) +
    ylab(NULL) + 
    coord_flip() 
  
  plot2 &lt;- ggplot(resModel2, aes(x=param, y=est)) + 
    geom_pointrange(limits, color="darkblue") + 
    scale_x_discrete("") + 
    geom_hline(yintercept=0, color="red") + 
    theme_bw() + 
    theme(text = element_text(size=10)) +
    ylab(NULL) + 
    coord_flip()
  
  library(gridExtra)
  grid.arrange(plot1, plot2, ncol=2)
  </code></pre>
  
  <p>... and end up with the following plot:</p>
  
  <p><a href="https://i.stack.imgur.com/6l7jr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6l7jr.png" alt="enter image description here"></a></p>
  
  <p>I was hoping to do the following:</p>
  
  <ol>
  <li>Sort coefficients by hand (in this order: Christian, Muslim, Female)</li>
  <li>Align coefficients for the same predictor across models (as done in the plot developed in Stata, where "Muslim girls" and "Christian girls" are plotted with no results in Plot1, making all predictors/parameters align across Model1 and Model 2)</li>
  <li>Include the regression coefficient in the plot (numbers above the dots representing point estimates in the regression analysis).</li>
  <li>Change names of predictors (e.g., from MUSLIMGI to "Muslim girls"), without editing the data frame.</li>
  <li>Adjust the x-scale to be the same for the two plots. 
  (Also, name the two models, I assume I should be able to figure out myself how to do that.)</li>
  </ol>
  
  <p>When searching for solutions, I found an R package called <code>coefplot</code> (a sort of add-on to <code>ggplot2</code>), but I am not sure whether <code>coefplot</code> can develop the plot I want and I would like to code things myself in <code>ggplot2</code> for flexibility. </p>
  
  <p>I also found <code>sjp.glm</code> (<a href="https://strengejacke.wordpress.com/2013/03/22/plotting-lm-and-glm-models-with-ggplot-rstats/" rel="nofollow noreferrer">https://strengejacke.wordpress.com/2013/03/22/plotting-lm-and-glm-models-with-ggplot-rstats/</a>), but I could not see how that function helps me when I have estimated statistical models outside R and need to plot parameters available in data frames. </p>