Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't save a ggplot2-diagram as svg with ggsave. #50

Open
christianlindell opened this issue Jan 22, 2025 · 2 comments
Open

Can't save a ggplot2-diagram as svg with ggsave. #50

christianlindell opened this issue Jan 22, 2025 · 2 comments

Comments

@christianlindell
Copy link

christianlindell commented Jan 22, 2025

I'm running Windows 11 and R 4.3.3 and RStudio 2023.12.1 with AGG as the default graphic engine. I can save a diagram produced with ggplot2 in svg-format if I use save_plot() from the sjPlot-package. But if I use ggsave() R crash with the message "R session arborted. R encountered a fatal error. The session was terminated". All packages are updated today (2025-01-22) so I'm using marquee v. 1.0.0 and ggplot2 v 3.5.1.

library(marquee)
library(grid)
library(ggplot2)
library(sjPlot)

md_text <-
  "# Lorem Ipsum
Lorem ipsum dolor sit amet, *consectetur* adipiscing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna **aliqua**."

cars <- sub("(\\w+)", "{.red ***\\1***}", rownames(mtcars))

dia <- ggplot(mtcars) + aes(disp, mpg, label = cars) +
  geom_marquee(size = 4) +
  ggtitle(md_text) +
  theme(plot.title = element_marquee(size = 12, width = 1))


save_plot("test.svg", fig = dia, width=20, height=20) # Works
ggsave(dia, filename = "test.svg", width = 20, height = 20) # R crash.

ggsave produce a file that contains the message: " This page contains the following errors:
error on line 397 at column 802: AttValue: ' expected
Below is a rendering of the page up to the first error."

ggsave(dia, filename = "test.png") works without any problems.

@petermott
Copy link

I can reproduce this using RStudio 2024.09.0 with Cairo graphics otherwise same as your setup.

@trevorld
Copy link

trevorld commented Feb 7, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants