0

I'm trying to enhance the dpi of a TIFF. image that I've made with ggplot2 but it's not saving anywhere.

Here goes the code

    tiff("test.tiff", units="in", width=300, height=300, res=300)
        ggplot(DatLong) +
        geom_bar(aes(y = Percentage, x = Station , fill = Groups), stat = "identity") + 
        theme_minimal() + 
        scale_fill_manual(values = c("#003366", "#3366CC", "#993300", "#660099"))
     dev.off()

After that this error keeps appearing

null device 1

I've tried shutting down R and start a new session but it keeps happening. It doesn't export the image file to the directory. Does anyone have a suggestion?

Cheers

  • 1
    Did you check the folder you used as `setwd()`? – Duck Jul 16 '20 at 22:06
  • You can use `ggplot2::ggsave` for an easier time – Richard Telford Jul 16 '20 at 22:21
  • Yes, I checked using setwd( ) but there's nothing too @Duck – Patricia Stelzer Jul 16 '20 at 23:09
  • Thanks @RichardTelford, I will try that – Patricia Stelzer Jul 16 '20 at 23:09
  • That message you get isn't an error. It's just a message letting you know which graphics device is in use after running `dev.off()`. How are you running this code? Are you running interactively or from a script? If the latter you need to make sure to `print()` your ggplot object to actually render it. Is a file being created at all? – MrFlick Jul 16 '20 at 23:15
  • @MrFlick I'm running from a script. How do I `print ( )` my object in ggplot? Where should I put it? When I try to export the image from the plot window it works just fine, it creates a file but the resolution isn't great. I actually use this tiff command yesterday and it did created a file, but it's not working today, not even to create a file – Patricia Stelzer Jul 16 '20 at 23:35
  • This is one of the [R FAQ](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f)s. You need `tiff(...); print(ggplot(...) + ...); dev.off()` where the `...` are the appropriate code chunks. The output will always go to your current working directory (`getwd()`) assuming there were no errors in any of the commands. – MrFlick Jul 16 '20 at 23:40
  • It worked! I also changed a bit the dimensions of the image. Thanks @MrFlick – Patricia Stelzer Jul 17 '20 at 00:04

0 Answers0