Save high resolution figures from R: 300dpi

Good day

I need help, please. I have been working on Rstudio for quite some time now. I am in this stage now, where I need high-resolution tiff images for publication purposes, for example, 300dpi. However, when I export images from Rstudio, the resolution of the tiff images is very low, 96 dpi. I even tried the commands published on the following websites:
https://www.r-bloggers.com/high-resolution-figures-in-r/ https://stackoverflow.com/questions/38907514/saving-a-high-resolution-image-in-r.

However, the properties of the tiff image say the resolution is 300 dpi, by judging the quality of the image it is not 300dpi. My images are in tiff format, see the tiff format file not supported for upload. Honestly, when I look at the tiff file with 96 dpi and the one for 300 dpi, the resolution of the 96dpi looks much better, not sure why this is the case. Is this a windows problem or a problem in Rstudio?

My codes: 96dbi
$ p1 = plot_bar(physeq_ASV_r, "description", fill="Phylum") + geom_bar(stat="identity", position="fill") + facet_grid(~environment, scales="free_x") + scale_y_continuous(labels=percent) + labs(x="Sample", y="Relative abundance") + scale_fill_manual(values = PhylaPalette) + theme(text=element_text(family="Arial", size=12))

My codes: 300dbi
tiff(filename="test.tiff", width=2300, height=2000, res=300)
$ plot_bar(physeq_ASV_r, "description", fill="Phylum") + geom_bar(stat="identity", position="fill") + facet_grid(~environment, scales="free_x") + scale_y_continuous(labels=percent) + labs(x="Sample", y="Relative abundance") + scale_fill_manual(values = PhylaPalette) + theme(text=element_text(family="Arial", size=12))
$dev.off()

Any help with this will be greatly appreciated. Is this a Rstudio issue or an issue with windows. I am using a 64-bit Windows operating system. Please help?

Regards
Sunette

Try using ggplot2::ggsave()

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

I am pretty sure @andresrcs 's reply will be what you're looking for. However, I have had troubles in the past saving really really big R plots at like 600 dpi at 30cm x 30cm with default saving because of Windows specifically and I got around the problem by using a different graphic engine.

This is an exmaple of png but I see you are able to change type to tiff.

library(Cairo)

Cairo::Cairo(
  30, #length
  30, #width
  file = paste("nameofplot", ".png", sep = ""),
  type = "png", #tiff
  bg = "transparent", #white or transparent depending on your requirement 
  dpi = 300,
  units = "cm" #you can change to pixels etc 
)
plot(p) #p is your graph object 
dev.off()

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.