1

I am trying to create a ggplot2 figure of 300 dpi using RStudio. i tried the command

tiff("test.tiff", units="in", width=5, height=5, res=300)

ggplot(Rrib, aes(YEAR, CLUSTER)) + geom_tile(aes(fill = SAMPLE_TYPE), colour="black", size = 1.3)+ scale_fill_manual(values = c("BOTH" = "red2", "ENV" = "forestgreen", "AFP" = "orange", "NONE" = "white"))

dev.off()

But instead R studio is not showing any out put in plot area. Your kind help will be highly appreciated

Nido
  • 55
  • 1
  • 1
  • 10
  • `myplot <- ggplot(...)` then `ggsave(myplot, "test.tiff", width = 5, height = 5, res = 300)` – Tung Nov 21 '19 at 15:23

1 Answers1

3

Use ggsave():

ggplot(Rrib, aes(YEAR, CLUSTER)) + geom_tile(aes(fill = SAMPLE_TYPE), colour="black", size = 1.3)+ scale_fill_manual(values = c("BOTH" = "red2", "ENV" = "forestgreen", "AFP" = "orange", "NONE" = "white"))
ggsave(‘test.tiff’,dpi=300)

In fact, the default dpi is 300, but I included the parameter in case you want to change it later.

SDS0
  • 500
  • 2
  • 8
  • I replaced the commas to fix it but the issue is i am not getting the out put in form of a graph in plot section – Nido Nov 21 '19 at 15:05
  • Kindly help in this regard – Nido Nov 21 '19 at 15:05
  • @SDSO Need your kind input i tried the command it says Saving 8.17 x 5.55 in image but nothing is appearing in Plot area – Nido Nov 21 '19 at 15:19
  • Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Nov 21 '19 at 15:21
  • 1
    Try assigning the ggplot to an object `p <- ggplot(Rrib, aes(...` and then use ggsave: `ggsave('test.tiff', p, device = "tiff", dpi = 200)` – benc Nov 21 '19 at 15:22
  • Dear benc thank u so much......after running these commands it says Saving 8.17 x 5.55 in image....where it is saving...from where i can get my plot – Nido Nov 21 '19 at 15:28
  • >Rrib <- "CLUSTER YEAR SAMPLE_TYPE – Nido Nov 21 '19 at 15:48
  • 1
    It should save in your working directory. But if you can specify the path in the `file =` term. e.g. `ggsave('c:/documents/my_project/test.tff', p, device = "tiff", dpi = 200)` – benc Nov 21 '19 at 16:01
  • Dear benc i got my ggplot but its dimensions are not exactly the same as i want them. i tried the command ggsave('C:/Users/Nayab/Desktop/test.tiff', p, device = "tiff", width=12, height=16, unit = "in", dpi = 300) but there is no output...your kind input will be highly appreciated – Nido Nov 21 '19 at 16:29