title: Cannot add ggproto objects together
body: <p>I'm currently working on an Rshiny app. I had to make multiple boxplots with several select inputs and a checkbox input. I've almost finished my task and now I just need to make it so that every time I change the Species selected, the scale stays the same (unless other variables have been input of course).</p>
  <p>My code looks like this:</p>
  <pre><code>library(shiny)
  library(palmerpenguins)
  library(dplyr)
  library(ggplot2)
  
  data &lt;- na.omit(penguins)
  
  colnames(data) &lt;- c(&quot;Species&quot;,
                      &quot;Island&quot;,
                      &quot;Bill Length (mm)&quot;,
                      &quot;Bill Depth (mm)&quot;, 
                      &quot;Flipper Length (mm)&quot;,
                      &quot;Body Mass (g)&quot;,
                      &quot;Sex&quot;,
                      &quot;Year&quot;)
  
  data.numeric &lt;- data[, c(3:6, 8)]
  
  data.categorical &lt;- data[, c(1,7)]
  
  
  ui &lt;- fluidPage(
    headerPanel(&quot;Penguin boxplots&quot;),
    selectInput(&quot;ycol&quot;, 
                &quot;Numeric Variable&quot;, 
                names(data.numeric),
                selected = names(data.numeric)[3]),
    selectInput(&quot;xcol&quot;,
                &quot;Categorical Variable&quot;,
                names(data.categorical),
                selected = names(data.categorical)[2]),
    checkboxInput(&quot;split&quot;,
                  &quot;Split levels by Island&quot;,
                  value = FALSE),
    selectInput(&quot;species&quot;,
                &quot;Species Type&quot;,
                c(&quot;Unspecified&quot;, levels(data$Species))),
    mainPanel(
      plotOutput(&quot;plot1&quot;)
    ))
  
  
  
  
  
  
  # 4. Use a select input to allow the user to view separate plotting 
  # panels for each species, with each plot panel on the same scale.
  
  
  server &lt;- function(input, output){
    output$plot1 &lt;- renderPlot({
      par(mar = c(5, 4.1, 0, 1))
      
      if (input$species == &quot;Unspecified&quot;){
        
        
        
        
        if (input$split) {
          ggplot(data, aes(x = data[[input$xcol]], y = data[[input$ycol]], fill = Island)) +
            geom_boxplot(na.rm = TRUE) +
            
            if (input$ycol == &quot;Bill Length (mm)&quot;){
                coord_cartesian(ylim = c(30, 60)) 
            } else if (input$ycol == &quot;Bill Depth (mm)&quot;){
              coord_cartesian(ylim = c(12.5, 21.5)) 
            } else if (input$ycol == &quot;Flipper Length(mm)&quot;){
              coord_cartesian(ylim = c(170, 232)) 
            } else if (input$ycol == &quot;Body Mass (g)&quot;){
              coord_cartesian(ylim = c(2500, 6500))
            } else if (input$ycol == &quot;Year&quot;){
              coord_cartesian(ylim = c(2006, 2009))
            } +
            xlab(input$xcol) +
            ylab(input$ycol) + 
            scale_x_discrete(labels = c(&quot;Female&quot;, &quot;Male&quot;)) +
            theme(text = element_text(size = 15))
          
        } else {
          ggplot(data, aes(x = data[[input$xcol]], y = data[[input$ycol]])) +
            geom_boxplot(na.rm = TRUE) +
            if (input$ycol == &quot;Bill Length (mm)&quot;){
              coord_cartesian(ylim = c(30, 60)) 
            } else if (input$ycol == &quot;Bill Depth (mm)&quot;){
              coord_cartesian(ylim = c(12.5, 21.5)) 
            } else if (input$ycol == &quot;Flipper Length(mm)&quot;){
              coord_cartesian(ylim = c(170, 232)) 
            } else if (input$ycol == &quot;Body Mass (g)&quot;){
              coord_cartesian(ylim = c(2500, 6500))
            } else if (input$ycol == &quot;Year&quot;){
              coord_cartesian(ylim = c(2006, 2009))
            } +
            xlab(input$xcol) +
            ylab(input$ycol) +
            theme(text = element_text(size = 15))
        }
        
        
        
        
        
        
        
      } else {
        
        
        
        
        
        data &lt;- data %&gt;%
          filter(data$Species == input$species)
        if (input$split) {
          ggplot(data, aes(x = data[[input$xcol]], y = data[[input$ycol]], fill = Island)) +
            geom_boxplot(na.rm = TRUE) +
            xlab(input$xcol) +
            ylab(input$ycol) + 
            scale_x_discrete(labels = c(&quot;Female&quot;, &quot;Male&quot;)) +
            theme(text = element_text(size = 15))
          
        } else {
          ggplot(data, aes(x = data[[input$xcol]], y = data[[input$ycol]])) +
            geom_boxplot(na.rm = TRUE) +
            xlab(input$xcol) +
            ylab(input$ycol) +
            theme(text = element_text(size = 15))
        }
      }
      
      
    })
  }
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  <p>The issue arises when I run the lines containing <code>else if (input$ycol == &quot;Year&quot;){ coord_cartesian(ylim = c(2006, 2009))}</code> as I get the following error: <strong>Cannot add ggproto objects together. Did you forget to add this object to a ggplot object?</strong></p>
  <p>I'm not sure where I'm going wrong here or if I'm just overlooking some sort of syntax error.</p>
  <p>p.s. The code isn't finished - I still need to add more code to control the scales for when the Species is not 'Unspecified', but I'm not doing that until this is figured out.</p>