title: How to reverse the Y axis range in dygraphs (R - shiny)?
body: <p>I am trying to reverse the Y axis scale in dygraphs embedded in a shiny app.</p>
  
  <p>My code - </p>
  
  <pre><code>  output$rainintensity &lt;- renderDygraph({
      withProgress(message = 'Loading graphs',{
        dygraph(rain_data(), group = "sync") %&gt;%
          dyAxis("y", "Rainfall intensity  (Inches/Hr)", valueRange = c(NULL, 0)) %&gt;%
          dySeries(input$rainguage,label="Rainfall intensity  (Inches/Hr)") %&gt;%
          dyOptions(includeZero = TRUE, retainDateWindow = TRUE, colors = "blue", plotter = 
                      "function barChartPlotter(e) {
                  var ctx = e.drawingContext;
                  var points = e.points;
                  var y_bottom = e.dygraph.toDomYCoord(0);  // see     http://dygraphs.com/jsdoc/symbols/Dygraph.html#toDomYCoord
  
                  // This should really be based on the minimum gap
                  var bar_width = 2/3 * (points[1].canvasx - points[0].canvasx);
                  ctx.fillStyle = e.color;
  
                  // Do the actual plotting.
                  for (var i = 0; i &lt; points.length; i++) {
                  var p = points[i];
                  var center_x = p.canvasx;  // center of the bar
  
                  ctx.fillRect(center_x - bar_width / 2, p.canvasy,
                  bar_width, y_bottom - p.canvasy);
                  ctx.strokeRect(center_x - bar_width / 2, p.canvasy,
                  bar_width, y_bottom - p.canvasy);
                  }
    }")
      })
    })
  </code></pre>
  
  <p>I get the following output graph -</p>
  
  <p><a href="https://i.stack.imgur.com/L1gZJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/L1gZJ.png" alt="enter image description here"></a></p>
  
  <p>It works when I set a definite valueRange as following:</p>
  
  <pre><code>output$rainintensity &lt;- renderDygraph({
      withProgress(message = 'Loading graphs',{
        dygraph(rain_data(), group = "sync") %&gt;%
          dyAxis("y", "Rainfall intensity  (Inches/Hr)", valueRange = c(1, 0)) %&gt;%
          dySeries(input$rainguage,label="Rainfall intensity  (Inches/Hr)") %&gt;%
          dyOptions(includeZero = TRUE, retainDateWindow = TRUE, colors = "blue", plotter = 
                      "function barChartPlotter(e) {
                  var ctx = e.drawingContext;
                  var points = e.points;
                  var y_bottom = e.dygraph.toDomYCoord(0);  // see     http://dygraphs.com/jsdoc/symbols/Dygraph.html#toDomYCoord
  
                  // This should really be based on the minimum gap
                  var bar_width = 2/3 * (points[1].canvasx - points[0].canvasx);
                  ctx.fillStyle = e.color;
  
                  // Do the actual plotting.
                  for (var i = 0; i &lt; points.length; i++) {
                  var p = points[i];
                  var center_x = p.canvasx;  // center of the bar
  
                  ctx.fillRect(center_x - bar_width / 2, p.canvasy,
                  bar_width, y_bottom - p.canvasy);
                  ctx.strokeRect(center_x - bar_width / 2, p.canvasy,
                  bar_width, y_bottom - p.canvasy);
                  }
    }")
      })
    })
  </code></pre>
  
  <p>Result -</p>
  
  <p><a href="https://i.stack.imgur.com/O7rmV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/O7rmV.png" alt="enter image description here"></a></p>
  
  <p>Is there any way I can reverse the Y axis range without setting a definite valueRange on the Y axis?</p>
  
  <p>I tried giving a reactive upper bound in the valueRange based on zooming. sort of like this - <code>valueRange = c(max(react_rain_data()*1.10, na.rm = TRUE), 0)</code> but it re renders the graphs every time the user zooms in.</p>
  
  <p>Note - According to the <a href="https://www.rdocumentation.org/packages/dygraphs/versions/1.1.1.4/topics/dyAxis" rel="nofollow noreferrer">documentation for dyAxis fucnction</a> :</p>
  
  <blockquote>
    <p>valueRange: Explicitly set the vertical range of the graph to c(low, high). This may be set on a per-axis basis to define each y-axis separately. If either limit is unspecified, it will be calculated automatically (e.g. c(NULL, 30) to automatically calculate just the lower bound).</p>
  </blockquote>
  
  <p>Thanks! </p>