0

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?

0Knowledge
  • 747
  • 3
  • 14
  • The issue is that by saving `plot+ theme_bw(base_size = 10, base_family = "Times New Roman")` you are overwriting all customized theme arguments with the defaults from theme_bw. – stefan Oct 21 '20 at 20:19

1 Answers1

0

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')
mostafiz67
  • 159
  • 1
  • 9