Graphics error: Plot file error

When creating a plot in RStudio I cannot add subsequent points, lines or legends. Here is a snip of some very simple code which is throwing up the error "Graphics error: plot file error" when I try and run line 5 onwards i.e. when trying to add points and a legend to the plot.

I have replicated the code in base R and it creates the plot correctly, so this must be an error in the R Studio GUI.
Does anyone have any ideas how to resolve this?
I am using RStudio version 1.1.453 with no packages loaded.
Many thanks in advance,

I am unable to reproduce your error, and the code works fine for me in RStudio:

x <- lynx[1:20]
y <- lynx[21:40]
z <- lynx[41:60]

plot(x, col = "blue", pch = 20)
points(y, pch = 20, col = "red")
points(z, pch = 20, col = "green")

legend(14, 6000, cex = 0.8, 
       col = c("blue", "red", "green"),
       pch = 20, 
       legend = c("1821-1840", 

Created on 2018-06-07 by the reprex package (v0.2.0).

1 Like

Hi @tbradley,
thanks for trying this! It works fine on my laptop (Mac) too, and I cannot for the life of me figure out why it isn't working on the desktop (Windows). Any ideas what might be causing it?

No I don't but googling your error message came up with a post on support.rstudio that suggested running this code before your plot:


The help page is here

1 Like

I found that post and tried x11(); and that didn’t work either. I’m at a total loss now. Thanks for looking though!

This works fine on my Windows VM. Can you provide the full error text that you are seeing?

What is the output of


on your machine?

1 Like