Graphics error: Plot rendering error Error in gzfile(file, "wb") :cannot open the connection

Does this work for you in R, but not in RStudio? (see FAQ below for disambiguation)