Rong
Rong

Reputation: 29

disppeared recession bar when copy as metafile

I am using ggplot to add recession bars in Rstudio. However, when I copy it as metafile and paste, the bars disappear. I also found this problem in matlab using recessionplot when copying as eps.

The following is my code.

bplot2 <- ggplot(yfit6.df, aes(x=date, y=yfit6,group = 1)) +
  scale_x_yearqtr(limits = c(min(yfit6.df$date), max(yfit6.df$date)),
                  format = "%YQ%q")+
  ylim(c(0,1))+geom_line(aes(y=yfit6.df$yfit6), colour = 'grey40',size=0.8) +
  ylab("Recession probability") +
  ggtitle("6 Month Ahead In-sample Forecasts")+theme(plot.title = element_text(lineheight=.9, face="bold",size=20),text = element_text(size=17))
print(bplot2)
###add recession bar###
bplot2<-bplot2+geom_area(data=as.data.frame(y6),aes(x=yfit6.df$date, y=y6),alpha=0.2)
print(bplot2)

The nomal graph looks like this enter image description here

However, when I copy it as metafile and paste, it is like this enter image description here

What should I do? Thanks

Upvotes: 1

Views: 633

Answers (1)

patrickmdnet
patrickmdnet

Reputation: 3392

The EPS files generated by R do not include transparency data, see this prior question.

I use the following workaround to generate EPS:

library(grDevices)
cairo_ps(filename='Figure.eps', width=7, height=5)
last_plot()
dev.off()

Upvotes: 1

Related Questions