title: R shiny brush zoom in plot ranges
body: <p><a href="https://i.stack.imgur.com/vX9Tb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vX9Tb.png" alt="enter image description here"></a>I developed an interactive correlation heat map at: <a href="https://lingjun.shinyapps.io/code/" rel="nofollow noreferrer">https://lingjun.shinyapps.io/code/</a></p>
  
  <p>The problem is that when I take a brush on the left plot to zoom in and get the right plot, there is always excessive labels for x and y axes on the left bottom corner in the right plot. I want the labels to cut off sharply.</p>
  
  <p>The code in the server class is:</p>
  
  <pre><code>observe({
      brush &lt;- input$zoom_brush
      if (!is.null(brush)) {
          ranges$x &lt;- c(round(brush$xmin), round(brush$xmax))
          ranges$y &lt;- c(round(brush$ymin), round(brush$ymax))
      } else {
          ranges$x &lt;- NULL
          ranges$y &lt;- NULL
      }
  })
  output$zoomplot &lt;- renderPlot({
  
  
          x.index &lt;- y.index &lt;- 1:300
  
          zoomplot &lt;- ggplot(melt(result[x.index, y.index]), aes(Var1, Var2, fill = value)) + geom_tile() + xlab("Q1") + ylab("Q2")+ scale_fill_gradient2(low = "blue",  high = "red",limits=c(-1, 1), guide=FALSE)+coord_cartesian(xlim = ranges$x, ylim = (ranges$y),expand=F)
  
  
  
          zoomplot
  
      },  height = 500, width = 500)
  </code></pre>
  
  <p>Here is the ui code:</p>
  
  <pre><code>shinyUI(fluidPage(
  
  
    titlePanel("SCIP survey response correlation heatmap"),
    selectInput("Correlation", 
            label = "Choose which to display",
            choices = list("corPSR", "Spearman", "difference"),
            selected = "corPSR"),
  
    fluidRow(
  column( width=5,
  
    h4("Click and drag to zoom in"),
    plotOutput("heatmap", 
               #click = "plot1_click",
               brush = brushOpts( id = "zoom_brush", resetOnNew = TRUE)),
    h4("Points near click"),
    verbatimTextOutput("click_info")),
  
  column(width=7,
  
    h4("Click to see details"),
    plotOutput("zoomplot", click="plot1_click"))
  </code></pre>
  
  <p>))</p>