R 如何使用带有所有自定义属性的ggsave保存自定义绘图?

R 如何使用带有所有自定义属性的ggsave保存自定义绘图?,r,ggplot2,plot,ggsave,R,Ggplot2,Plot,Ggsave,我有一个绘图,然后我更改了ggplot的一些默认属性,如font-face、font-color、bold等。但是,当我使用命令或从Rstudio的绘图打开绘图时,图像包含我的所有自定义属性 但是,当我使用ggsave保存绘图时,它不会显示和保存图像的所有自定义属性。更具体地说,我保存的图像没有显示themes()中给出的属性 我的代码如下 plot <- ggplot(plot_df, aes(Region, diff, fill = Region))+ geom_bar(stat

我有一个绘图,然后我更改了
ggplot
的一些默认属性,如
font-face、font-color、bold
等。但是,当我使用命令或从
Rstudio的绘图
打开绘图时,图像包含我的所有自定义属性

但是,当我使用
ggsave
保存绘图时,它不会显示和保存图像的所有自定义属性。更具体地说,我保存的图像没有显示
themes()
中给出的属性

我的代码如下

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") 
有没有办法使用ggsave保存原始绘图?

只需将
theme\u bw()
更改为
theme()
。希望这能奏效

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

问题在于,通过保存
plot+theme\u bw(base\u size=10,base\u family=“Times New Roman”)
您将使用theme\u bw的默认值覆盖所有自定义主题参数。
ggsave("~/My/plot.png", plot = plot+
         theme(), width = 10, height = 8, dpi = 150, units = "in", device='png')