Open markbneal opened 4 years ago
I've done some additional testing with the code from geom_xspline()
help file to identify:
1) Exactly which options in geom_xspline()
are causing issues with ggsave()
-> linetype=2
and spline_shape = -0.5
are problems, a simple geom_xspline(size=0.5)
works with ggsave()
2) Alternative save plot methods and whether they work -> cowplot save doesn't. base png()
and pdf()
work, even with options that are problematic:
#from help for geom_xspline ############################################################
library(ggalt)
library(cowplot)
set.seed(1492)
dat <- data.frame(x=c(1:10, 1:10, 1:10),
y=c(sample(15:30, 10), 2*sample(15:30, 10),
3*sample(15:30, 10)),
group=factor(c(rep(1, 10), rep(2, 10), rep(3, 10)))
)
ggplot(dat, aes(x, y, group=group, color=group)) +
geom_point() +
geom_line()
#works
ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point() +
geom_line() +
geom_smooth(se=FALSE, linetype="dashed", size=0.5)
ggsave("my plot 5.png")
#doesn't ggsave, depending on geom_xspline parameters
p1 <- ggplot(dat, aes(x, y, group=group, color=factor(group))) +
geom_point(color="black") +
geom_smooth(se=FALSE, linetype="dashed", size=0.5) +
# geom_xspline(size=0.5) #will save with ggsave - this is the version in help
# geom_xspline(linetype=2) #crashes with ggsave
geom_xspline(spline_shape = -0.5) #crashes with ggsave
p1
#ggsave("my plot 6.png")
#save_plot("p1.png", p1) #using cowplot save, also doesn't work
#works
#http://www.sthda.com/english/wiki/creating-and-saving-graphs-r-base-graphs
pdf("my plot 9.pdf")
# 2. Create a plot
p1
# Close the pdf file
dev.off()
#works
png("my plot 10.png")
p1
dev.off()
Issue at ggplot can be reopened if it is clear issue is at that end of the chain. Obviously we can sidestep the problem temporarily by saving with png(), but it would be nice to solve.
I could plot to png with ggsave only before plotting to the window. And plotting to the plot window worked after ggsave.
The plot viewer crash occurs on my computer, and on Rstudio cloud, due to some interaction with
geom_xspline()
I don't know if this is a ggalt issue or a ggsave issue, or an rstudio IDE issue. In any case I've raised it at the rstudio community, at: https://community.rstudio.com/t/rstudio-plot-viewer-crashes-with-ggsave-and-ggalt-combination-desktop-and-cloud/63822 . I've also raised on ggplot github (https://github.com/tidyverse/ggplot2/issues/3974)See cloud project here (https://rstudio.cloud/project/1219353).