ggplot2 plots are missing components in the plot pane

I've recently developed a problem with the plot pane in RStudio ver. 1.4.1103 (R ver. 4.1.0) running on a Windows 10 virtual machine. I have a script that generates four plots, each with about 7,500 data points. The plots usually work correctly if I run the whole script from start to finish (takes about four minutes). But I often want to fine-tune the appearance of the graphs, so after the script finishes, I make some adjustments to the ggplot2 options, I select a block of code that includes the ggplot2 function, and I execute just that one block. In that case, the plots often come out missing components, like annotations, axes, and the box around the plot. Interestingly, even if the plot looks wrong in the plot pane, it looks correct if I click on the zoom icon, and it's also correct if I save the plot as a PNG file. This is a fairly new problem.

Here's an example of what a faulty plot looks like in the plot pane:

It's supposed to have axes and a box around the graph. Sometimes, the annotations are missing (though not in this particular example).

The problem is sporadic, and I don't have a reproducible example.

Here's what I've tried to solve the problem:

  • Increasing the size of the plot pane in the RStudio IDE
  • Running before plotting
  • Running gc() before plotting
  • Updating to the latest version of R
  • Updating all the packages

None of this helps. I'm willing to try reinstalling RStudio, if necessary.

Thanks for any help.

Thanks for the suggestion, Martin, but installing the preview version of RStudio didn't solve the problem. In fact, it introduced a new problem. Now there is some weirdness with the console window. I have a cat('\f') statement at the beginning of my script. In previous versions of RStudio, this statement acted to clear the console. It now clears the console, but it also prevents any subsequent output from appearing. If I remove the cat('\f') statement, I do get output, but the console window doesn't scroll properly. The output runs off the bottom of the window, and the only way to see it is to use the mouse to manually move the scrollbar down. This problem never occurred with previous versions of RStudio.

Update: The issue with cat('\f') and the scrolling issue were both fixed by un-checking Tools -> Global Options -> Console -> Limit visible console output.

I figured out the problem with the missing components in the ggplot2() graphs. I had one data point that lay outside the boundaries of the graph. That data point would generate a warning message from ggplot, but I just ignored the message. When troubleshooting this problem, I tried dropping that one offending data point from the dataframe, and I found that I no longer had issues with missing axes, notations, etc.

What still puzzles me about this issue is that it wasn't consistent. Sometimes the graphs looked right, and sometimes they had missing components.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.