R: Not able to save the plot

10,033

From the comments I gather that I was right, you need to print the resulting ggplot2 object in order to show the plot, see also R FAQ 7.22.

Share:
10,033
Rachit Agrawal
Author by

Rachit Agrawal

Love coding.

Updated on June 04, 2022

Comments

  • Rachit Agrawal
    Rachit Agrawal almost 2 years

    I am generating a plot which I am able to see in the RMarkdown output but whenever I am trying to save it, I am getting just a blank(white) image. I am just adding following two lines before and after plot

    png("Output.png")
    #Plot code
    dev.off()
    

    It was working. And suddenly it stopped working. Can someone help me on this??

    edit

    When I do it with pdf

    pdf("output.pdf")
    #plot code
    dev.off()
    

    I am getting error as:

    There was error opening this document. This document cannot be opened because it has no pages. 
    

    Thanks.

  • AHegde
    AHegde about 7 years
    Hi, this happens to me even without using ggplot2 (I'm using base graphics "boxplot" function). Any idea why this might be happening?
  • Paul Hiemstra
    Paul Hiemstra about 7 years
    @AHegde this problem is not related to this one as the boxplot function does not use grid graphics. Please create a new question which includes a reproducible example.