title: Why is my chart not showing in RStudio's "Plots" pane?
body: <p>I have written several functions that connect to a server and gather some data and mutates those data.  One of the functions visualises the data also.</p>
  
  <p>As I always need to run all six functions - and because I wrote them as and when I needed them - I decided it would be more efficient to combine them into a single, larger function (~400 lines, possibly going down to ~350 soon after some cleansing) rather than having to run six separate functions independently one after the other.</p>
  
  <p>Before combing the functions, the one that produced the visualisation worked perfectly in that it showed up in the <code>Plots</code> window in RStudio.</p>
  
  <p>Since combining the functions, the visualisation is not showing up.</p>
  
  <p>I added a line to show whether or not the chart has been generated successfully, and it always is; however, I don't see the output any more.</p>
  
  <p>Here is the code for the chart:</p>
  
  <pre><code>if(chart == TRUE){
      ggplot(plugin_displays[plugin_displays$date &lt;= end_date, ], aes(fill = type)) +
        geom_col(aes(x = time, y = count),
                 colour = "black",
                 position = "stack") +
        geom_text(aes(x = time, y = total, label = total),
                  hjust = -0.15,
                  vjust = 0.15,
                  size = 3,
                  colour = "black",
                  angle = 90) +
        scale_y_continuous(limits = c(0, max(plugin_displays$total) * 1.02)) +
        labs(title = paste0("Plugin Loads &amp; Unloads ", start_date, " - ", end_date),
             x = "Time",
             y = "Count") +
        facet_grid(.~date) +
        scale_fill_manual(values=c("forestgreen", "red")) +
        theme(plot.title = element_text(size = 25,
                                        face = "bold",
                                        colour = "black"),
              panel.grid.minor.x = element_blank(),
              panel.grid.major.x = element_blank(),
              axis.text = element_text(colour = "black",
                                       angle = 90))
      print("Chart printed.")
    } else {
      print("Chart not shown by default.  Set chart = TRUE to display chart")
    }
  </code></pre>
  
  <p>By default, <code>chart</code> is set to <code>FALSE</code> as a chart isn't always needed.  To generate the chart, a user specifies either <code>TRUE</code> or <code>chart = TRUE</code> when calling the function and it generates the graph (using an <code>if/else</code>); otherwise, it is simply a waste of processing power.</p>
  
  <p>I thought that perhaps the order of processes occurring would have affected the output, so I moved the plot down to the bottom of the script and it still doesn't show up in the <code>Plots</code> pane, despite the <code>"Chart printed."</code> message showing.</p>
  
  <p>The function as a whole executes perfectly and the desired output is precisely what I want it to be.</p>
  
  <p>There are no errors at any point during the execution phase and the data frames are all as expected, with nothing wrong.</p>
  
  <p>If I split the visualisation function out, it works independently with no issues.  If I put it back into the function, it still executes successfully but there is no visualisation.</p>
  
  <p>What could be causing this?</p>
  
  <p><strong>UPDATE (6TH JUNE 2018):</strong></p>
  
  <p>Somebody suggested wrapping the plot in <code>print</code>.  This has worked in the sense that the plot now appears, albeit in a new window - this isn't what I want, which is for the plot to remain within the RStudio IDE.</p>