title: Legend changing the size of ggplot figure in shiny
body: <p>I have a ggplot in Shiny, which uses geom_point to plot some data. I have it setup so that when a checkbox is checked, an aesthetic is added which colours the data into two separate variables. This also creates a legend. My problem is that when this legend appears, it 'takes' space from the plot and the plot becomes slightly smaller. Is there a way I can fix the size of the plot so that the legend appears without altering the plot size?</p>
  
  <pre><code>ui &lt;- fluidPage(
    titlePanel("Transfers Analysis App"),
  
    sidebarLayout(
      sidebarPanel(
        checkboxInput("Outage", "Show Outages", FALSE)
      ),
      mainPanel(
        plotOutput("plot1", height = "600px", width = "100%", hover = hoverOpts(id = "plot_hover")),
        verbatimTextOutput("hover_info")
      )
    )
  )
  
  server &lt;- function(input, output) {
  
    output$plot1 &lt;- renderPlot({
      Outage &lt;- input$Outage
  
      g &lt;- ggplot(data, aes(Date, NUMBER_OF_TRANSFERS)) + geom_point() 
  
      if (Outage == TRUE) 
        g &lt;- g + geom_point(aes(color = Outage))  + scale_colour_manual(breaks = c("Outage", "No Outage", "Day After an Outage", "Both"), name= "Legend", values=c( "black", "red", "blue")) + theme(legend.position="bottom")
  
      plot(g)
    })
  }
  
  shinyApp(ui, server)
  </code></pre>
  
  <p>note: my actual code has a lot more features in than this which I have cut out for simplicity. </p>