在我使用 R 中的 ggsave 保存后,Geom-ribbon 消失了

Geom-ribbon disappear after I saved it using ggsave in R

我在 R 中的 ggplot2 中使用 geom-ribbon 生成了下图:

但是我用ggsave保存这张图后,得到的图是

突然,缎带不见了。 我正在使用以下命令:

plotData<-ggplot(data = pd, aes(x = date, y = observed)) + geom_line(aes(color = "1"), size=0.95) +
        geom_line(aes(y = fitted,color="2"),size=0.95) + 
        geom_line(aes(y = forecast,color="3"), size=0.95) +
        scale_colour_manual(values=c("red", "blue","black"),labels = c("Observed", "Fitted", "Forecasted"), name="Data")+
        geom_ribbon(aes(ymin = lo95, ymax = hi95), alpha = .25)+
          #theme_bw()+
          #xlab("Time in Decades") + 
          #ylab(expression(paste ("Chl-a [mg/", m^3,"]"))) +
        scale_x_date(name = "Year", date_breaks = "2 year", labels=date_format("%Y ")) +
        scale_y_continuous(name =expression(paste ("Chl-a [mg ", m^-3,"]")))+
        theme(axis.text.x = element_text(size = 20, color="black" ,margin = margin(t = 10, r = 0, b = 0, l = 0), face="bold")) +
        theme(axis.text.y = element_text(size = 20,color="black",margin = margin(t = 0, r = 10, b = 0, l = 0), face="bold")) + 
        theme(axis.title.x = element_text(size = 35,margin = margin(t = 30, r = 0, b = 0, l = 0), face="bold")) +
        theme(axis.title.y = element_text(size = 35,margin = margin(t = 0, r = 30, b = 0, l = 0), face="bold")) + 
        #ggtitle("title")
        theme(legend.title = element_text(size = 20, face="bold"), legend.text = element_text(size =20, face="bold"))
       

plotData

ggsave(plotData, path="C:\Users\graphs",  file="dataaaa3.eps", device="eps", width=13, type = "cairo")
dev.off()

感谢您的帮助。

PS:我收到以下警告:

Removed 24 rows containing missing values (geom_path).

由于您没有提供数据,我们无法重现您的问题。但是,导出时应该会收到警告,例如

In grid.Call.graphics(C_polygon, x$x, x$y, index) :
  semi-transparency is not supported on this device: reported only once per page

这基本上意味着 R 无法将透明层导出到 .eps 文件。我不知道你的具体用例,但对于在 LaTeX 中使用,我在导出到 .pdf.

方面有很好的经验

您必须将设备更改为 'cairo_ps':

ggsave("dataaaa3.eps", device=cairo_ps)