Closed
Description
Hello,
I am encountering an issue with ggsave
on linux that does not occur on macos. The steps below show that explicitly calling the png
device and then printing the plot object works, but using ggsave
with the same plot object throws the error shown. I have found that substituting the 'jpg' device in egnerates the same error. The output of traceback()
and sessionInfo()
are included.
We have the work around, but we would love to know how to use ggsave
successfully.
Thanks!
Ben
library(ggplot2)
gg = ggplot(mtcars, aes(wt, mpg)) +
geom_point(colour = "red", size = 3)
# this works and the image is produced
png("my_other_image.png")
print(gg)
dev.off()
#> png
#> 2
# this doesn't work and the image is not produced
ggsave(filename = "my_image.png",
device = "png",
plot = gg)
#> Saving 7 x 5 in image
#> Error in f(...): Graphics API version mismatch
traceback()
# 4: f(...)
# 3: png_dev(..., res = dpi, units = "in")
# 2: dev(filename = filename, width = dim[1], height = dim[2], bg = bg,
# ...)
# 1: ggsave(filename = "my_image.png", device = "png", plot = gg)
sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-redhat-linux-gnu
#> Running under: Rocky Linux 8.10 (Green Obsidian)
#>
#> Matrix products: default
#> BLAS/LAPACK: /usr/lib64/libopenblaso-r0.3.15.so; LAPACK version 3.9.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
#> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
#> [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
#>
#> time zone: America/New_York
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] ggplot2_3.5.1
#>
#> loaded via a namespace (and not attached):
#> [1] vctrs_0.6.5 cli_3.6.3 knitr_1.48 rlang_1.1.4
#> [5] xfun_0.47 generics_0.1.3 textshaping_0.4.0 labeling_0.4.3
#> [9] glue_1.8.0 colorspace_2.1-1 htmltools_0.5.8.1 ragg_1.3.2
#> [13] scales_1.3.0 fansi_1.0.6 rmarkdown_2.28 grid_4.4.2
#> [17] evaluate_0.24.0 munsell_0.5.1 tibble_3.2.1 fastmap_1.2.0
#> [21] yaml_2.3.10 lifecycle_1.0.4 compiler_4.4.2 dplyr_1.1.4
#> [25] fs_1.6.4 pkgconfig_2.0.3 rstudioapi_0.17.1 systemfonts_1.1.0
#> [29] farver_2.1.2 digest_0.6.37 R6_2.5.1 tidyselect_1.2.1
#> [33] reprex_2.0.2 utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3
#> [37] tools_4.4.2 withr_3.0.2 gtable_0.3.6
Created on 2024-12-12 with reprex v2.0.2
Metadata
Metadata
Assignees
Labels
No labels