How to save a customize plot using ggsave with all customized properties?

629 views Asked by At

I have a plot and then I changed some by default properties of ggplot like font face, font color, bold etc. However, when I am opening the plot using command or from Rstudio's plot the image contains all my customize property.

However, when I am saving the plot using ggsave it is not showing and saving all the customized properties of the image. More specifically my saved image is not showing the properties given in them().

My code is given below

plot <- ggplot(plot_df, aes(Region, diff, fill = Region))+
  geom_bar(stat = "identity", width = 0.8, position = position_dodge(width = 0.9))+
  theme_bw()+
  
  theme(panel.grid = element_blank(),
        plot.title = element_text(color = "black", face = "bold"),
        axis.text.x = element_text(colour="black",size=10,face="bold"),
        axis.text.y = element_text(colour="black",size=10,face="bold")
  )+
  xlab("Region")+
  ylab("Average Region Rainfall (mm)")+
  ggtitle("Average Region Ranfall") 

Saving code using ggsave

ggsave("~/My/plot.png", plot = plot+
         theme_bw(base_size = 10, base_family = "Times New Roman"), width = 10, height = 8, dpi = 150, units = "in", device='png')

Is there any way to save the original plot using ggsave?

1

There are 1 answers

0
mostafiz67 On BEST ANSWER

Just change theme_bw() with theme(). Hopefully, this will work.

ggsave("~/My/plot.png", plot = plot+
         theme(), width = 10, height = 8, dpi = 150, units = "in", device='png')