0

I'm trying to save a boxplot with points and line of individual samples on a boxplot with ggplot as an .eps file. By uncommenting one of the two last line to save, one can save either as a .png or .eps file. However, when comparing the two saved figures, there are several issues with the png file:

  • First (the most important point to me): the lines between the samples disappears
  • The filling of the boxplot disappeared
  • The ordering of the data changed.

How can we fix it so that the .eps figure looks exactly like the .png file

library(dplyr) 
library(ggplot2)
width = 7
height = 4
dpi = 100

df <- data.frame(
    result = rnorm(48, 1,3),
    time = rep(c('t1', 't2', 't3', 't4'), 12  ),
    subject = rep(c(1:12), each=4),
    gender = rep (c('M', 'F'), 6, each=4) )

pd = ggplot2::position_jitterdodge(dodge.width = 0.75, jitter.width = 0.3, seed = 1)
df %>% 
  ggplot (aes(x= time, y=result, fill=gender))+
  geom_boxplot(alpha=0.2)+
  geom_point(aes(color = gender, group=subject),position = pd)+
  geom_line(aes(color=gender, group=subject), 
            position=pd, alpha=0.3)+
  scale_fill_brewer(palette = 'Set1')+
  scale_color_brewer(palette = 'Set1')

ggsave(("try.png"), dpi = dpi, width = width, height = height)
#ggsave(("try.eps"), dpi = dpi, width = width, height = height, device = "eps")

Result .png:

enter image description here

Result .eps:

enter image description here

Note: I copied the code from this question

ecjb
  • 5,169
  • 12
  • 43
  • 79
  • 1
    I assume you saw the warning message that code produced: "semi-transparency is not supported on this device: reported only once per page". The EPS format does not natively support transparency and you've set an `alpha` for your boxes and lines. Use the alternative suggestions in the duplicate for possible workarounds. – MrFlick Jan 19 '21 at 07:42
  • Many thanks @MrFlick `device=cairo_ps, fallback_resolution = 600` worked indeed! – ecjb Jan 19 '21 at 07:48

0 Answers0