title: How to scale/transform graphics::plot() axes with any transformation, not just logarithmic (for Weibull plots)?
body: <p>I am building an R package to display Weibull plots (using <code>graphics::plot</code>) in R. The plot has a log-transformed <em>x</em>-axis and a Weibull-transformed <em>y</em>-axis (for lack of a better description). The two-parameter Weibull distribution can thus be represented as a straight line on this plot.</p>
  
  <p>The logarithmic transformation of the <em>x</em>-axis is as simple as adding the <code>log="x"</code> parameter to <code>plot()</code> or <code>curve()</code>. How can I supply the <em>y</em>-axis transformation in an elegant way, so that all graphics-related plotting will work on my axis-transformed plot? To demonstrate what I need, run the following example code:</p>
  
  <pre><code>## initialisation ##
  beta     &lt;- 2;eta &lt;- 1000
  ticks    &lt;- c(seq(0.01,0.09,0.01),(1:9)/10,seq(0.91,0.99,0.01))
  F0inv    &lt;- function (p) log(qweibull(p, 1, 1))
      # this is the transformation function
  F0       &lt;- function (q) exp(-exp(q))
      # this is the inverse of the transformation function
  weibull  &lt;- function(x)pweibull(x,beta,eta)
      # the curve of this function represents the weibull distribution 
      # as a straight line on weibull paper
  weibull2 &lt;- function(x)F0inv(weibull(x))
  </code></pre>
  
  <p>First an example of a Weibull distribution with <code>beta=2</code> and <code>eta=1000</code> on a regular, untransformed plot:</p>
  
  <pre><code>## untransformed axes ##
  curve(weibull ,xlim=c(100,1e4),ylim=c(0.01,0.99))
  abline(h=ticks,col="lightgray")
  </code></pre>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/SzEVQ.png" alt="plot1"></p>
  </blockquote>
  
  <p>This plot is useless for Weibull analysis. Here is my currently implemented solution that transforms the data with function <code>F0inv()</code> and modifies the <em>y</em>-axis of the plot. Notice that I have to use <code>F0inv()</code> on all <em>y</em>-axis related data.</p>
  
  <pre><code>## transformed axis with F0inv() ##
  curve(weibull2,xlim=c(100,1e4),ylim=F0inv(c(0.01,0.99)),log="x",axes=F)
  axis(1);axis(2,at=F0inv(ticks),labels=ticks)
  abline(h=F0inv(ticks),col="lightgray")
  </code></pre>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/YANtA.png" alt="plot2"></p>
  </blockquote>
  
  <p>This works, but this is not very user-friendly: when the user wants to add annotations, one must always use <code>F0inv()</code>:</p>
  
  <pre><code>text(300,F0inv(0.4),"at 40%")
  </code></pre>
  
  <p>I found that you can achieve a solution to my problem using <code>ggplot2</code> and scales, but I don't want to change to a graphics package unless absolutely necessary since a lot of other code needs to be rewritten.</p>
  
  <pre><code>## with ggplot2 and scales ##
  library(ggplot2)
  library(scales)
  weibull_trans &lt;- function()trans_new("weibull", F0inv, F0)
  qplot(c(100,1e4),xlim=c(100,1e4),ylim=c(0.01,0.99),
      stat="function",geom="line",fun=weibull) + 
      coord_trans(x="log10",y = "weibull") 
  </code></pre>
  
  <blockquote>
    <p><img src="https://i.stack.imgur.com/eyB8S.png" alt="plot3"></p>
  </blockquote>
  
  <p>I think that if I could dynamically replace the code for applying the logarithmic transformation with my own, my problem would be solved.</p>
  
  <p>I tried to find more information by Googling "R axis transformation", "R user coordinates", "R axis scaling" without useful results. Almost everything I have found dealt with logarithmic scales.</p>
  
  <p>I tried to look into <code>plot()</code> at how the <code>log="x"</code> parameter works, but the relevant code for <code>plot.window</code> is written in C – not my strongest point at all.</p>