title: R - ggplot2 in Shiny - How to extract/get/set current x/y/both axis range from a previous plot/graph?
body: <p>I am using the Shiny package. 
  I have a ggplot2 graph and its bounds are updated automatically whenever the user changes the input.  I have a control that says "Fix current axis range". </p>
  
  <p><strong>I want the control to determine the current x and/or y ranges of the previous Shiny graph and use it as input for the new one about to be created.</strong> </p>
  
  <p>I planned to use a function like coord_cartesian to fix the desired bound. </p>
  
  <p>Another option is simply having a function with the option of fixing the x, y, or both bounds but I had no luck finding one. </p>
  
  <p>How can this be done ?</p>
  
  <p>-------------<strong>update</strong>---------------</p>
  
  <p>Failed attempt with a global variable because coord_cartesian doesn't return what I expected. What does it return (I couldn't find documentation) ? </p>
  
  <pre><code>#---------------SNIPPET---------------
  #global variable
  yaxis
  
  #renderPlot 
  if(input$yaxis == "default") {
      y &lt;- coord_cartesian(ylim = c(-1, 1))
      yaxis &lt;- y
  }
  else if(input$yaxis == "variable") {
  
      yaxis &lt;- ggplot_build(q)$panel$ranges[[1]]$y.range
  }
  else if(input$yaxis == "fixed") {
      y &lt;- yaxis
  }
  
  print(q + y)
  </code></pre>