0

I have written code for a plot which is correct, yet I cannot save it as a png file. I used the png() function before I plotted and used dev.off() after and it won't save. I didn't include the reading of the data and creation of variables btw. (Mac)

I've tried everything, nothing works. Is there a way to save fullplot?

png(filename = "plot_3.png", width = 480, height = 480)

p1 <- (ggplot(PTsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("Point") + 
xlab("Date") + ylab("Total Emission"))
p2 <- (ggplot(NPTsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                         , fill="gray") + ggtitle("NonPoint") + 
xlab("Date") + ylab("Total Emission"))
p3 <- (ggplot(Rsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("Road") + 
xlab("Date") + ylab("Total Emission"))
p4 <- (ggplot(NRsum, aes(x=Group.1, y =x))
              + geom_bar(stat="identity", color="black"
                     , fill="gray") + ggtitle("NonRoad") + 
xlab("Date") + ylab("Total Emission"))
fullplot <- multiplot(p1,p2,p3,p4,cols=2)

dev.off()

I expected a file called plot3.png but it wasn't there

  • 1
    Hi. Please make sure to review how to make a [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) example and what constitutes a good SO question. This question is missing data and package loading – Conor Neilson Mar 24 '19 at 17:15
  • To save a `ggplot` you can use `ggsave(filename = "plot_3.png", plot = 'p1', device = 'png')` – Conor Neilson Mar 24 '19 at 17:17
  • try if adding a line with "fullplot" before "dev.off()" helps – Oka Mar 24 '19 at 17:44
  • Try adding `print(fullplot)` prior to the `dev.off()` function call. – Dave2e Mar 24 '19 at 21:31
  • Possible duplicate of [How to save a plot as image on the disk?](https://stackoverflow.com/questions/7144118/how-to-save-a-plot-as-image-on-the-disk) – divibisan Apr 02 '19 at 17:50

0 Answers0