title: Get margin line locations (mgp) in user coordinates
body: <p>I am trying to do some non-conventional plot labeling and would like a way to convert the <code>line</code> parameter in <code>mtext</code> and <code>axis</code> to user coordinates. </p>
  
  <p>In other words I would like to convert the values in <code>par()$mgp</code> to user coordinates.</p>
  
  <p>This illustrates the problem:</p>
  
  <pre><code>setup_plot &lt;- function() {
    par(mar = c(2, 10, 2, 2), oma = rep(2, 4))
    plot.new()
    plot.window(xlim = c(0, 1), ylim = c(0, 1))
    box(which = "plot", lwd = 2, col = "gray40")
    box(which = "figure", lwd = 2, col = "darkred")
    box(which = "outer", lwd = 2, col = "darkgreen")
    text(x = 0.5, y = 0.5, 
         labels = "Plot Region", 
         col = "gray40", font = 2)
    mtext(side = 3, text = "Figure region", line = 0.5, col = "darkred", font = 2)
    mtext(side = 3, text = "Device region", line = 2.5, col = "darkgreen", font = 2)
    for (i in 0:9) {
      mtext(side = 2, col = "darkred", text = paste0("Line", i), line = i)
    }
  }
  </code></pre>
  
  <p>I have tried two different approaches.    </p>
  
  <pre><code>## Try one approach where a line is the string height of "M"
  setup_plot()
  xline = strheight("M", units = "user")
  abline(v =  par()$usr[1] - 0:9*xline, 
         xpd = TRUE, lty = "dashed", col = "gray40")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/8qtfe.png" alt="Lines do not line up with the text">    </p>
  
  <pre><code>## Try a second approach defining a line using par()$mai &amp; par()$mar
  setup_plot()
  xline = abs(grconvertX(unique(par()$mai/par()$mar), "inches", "user"))
  abline(v =  par()$usr[1] - 0:9*xline, 
         xpd = TRUE, lty = "dashed", col = "gray40")
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/dwDW1.png" alt="Only one line is drawn"></p>
  
  <p>How do you get the line positions in user coordinates?</p>
  
  <p><strong>NOTE:</strong> The figures here are 4 inches by 6 inches. Changing the output size changes how the lines are drawn -- which also does not make sense to me. </p>