【发布时间】:2020-10-21 20:07:10
【问题描述】:
我有一个情节,然后我更改了ggplot 的一些默认属性,例如font face, font color, bold 等。但是,当我使用命令或Rstudio's plot 打开情节时,图像包含我所有的自定义属性。
但是,当我使用ggsave 保存绘图时,它没有显示和保存图像的所有自定义属性。更具体地说,我保存的图像没有显示them() 中给出的属性。
我的代码如下
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保存代码
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')
有没有办法使用 ggsave 保存原始图?
【问题讨论】:
-
问题在于,通过保存
plot+ theme_bw(base_size = 10, base_family = "Times New Roman"),您将使用 theme_bw 的默认值覆盖所有自定义主题参数。