3

I used geom-ribbon in ggplot2 in R to generate the following graph:

enter image description here

however, after I used ggsave to save this graph, the obtained figure is enter image description here

Suddenly the ribbon disappeared. I am using the following command:

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()

Thanks for your help.

PS: I am getting the followig warning:

Removed 24 rows containing missing values (geom_path).

Community
  • 1
  • 1
Nizar
  • 145
  • 8

2 Answers2

3

You have to change the device to 'cairo_ps':

ggsave("dataaaa3.eps", device=cairo_ps)
00schneider
  • 698
  • 9
  • 21
0

As you have not provided your data, we cannot reproduce your problem. However, you should be getting a warning when you export, such as

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

This basically means that R cannot export transparent layers to .eps files. I don't know about your particular use case, but for use in LaTeX I have had good experience with exporting to .pdf.

shs
  • 3,683
  • 1
  • 6
  • 34