1.

Can plots be exported as image files or other file formats in R? Explain briefly.

Answer»

Response:

We could easily save our plots as images directly from R using an editor such as RStudio. This way of saving, however, does not provide much flexibility. If we want to customize our images, we need to have an approach as to how to export plots from the R code itself.

We can use “ggsave” function to accomplish this.

We can save the plots in different formats such as jpeg, tiff, pdf, svg etc. We can also use various parameters to change the SIZE of the image PRIOR to exporting it or saving it in a path or location.

# Saving as jpeg format

ggsave(filename = “PlotName1.jpeg”, plot=Image_plot )

# Saving as tiff format

ggsave(filename = “PlotName1.tiff”, plot=Image_plot )

# Saving as pdf format

ggsave(filename = “PlotName1.pdf”, plot=Image_plot )

# Saving as tiff format with change in size

ggsave(filename = “PlotName1.tiff”, plot=Image_plot , width=14, height=10, UNITS=”CM”)


Discussion

No Comment Found