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
:
Result .eps
:
Note: I copied the code from this question