Closed myominnoo closed 5 months ago
Hi,
Yes, also ran into similar issue. There is a PR from ggplot2 team that should hopefully resolve errors. See #25.
Best, Sam
I tried and indeed found that the issue is caused by an incompatibility between the versions of ggplot2 and ggprism. I observed that the problem does not occur when using the following version combination:
packageVersion("ggprism") [1] ‘1.0.4’ packageVersion("ggplot2") [1] ‘3.4.4’
The issue is that ggplot2 has deprecated that theme element and provides fallback in the theme()
function. In the line below, the ggprism theme uses a template theme for formatting the return value:
https://github.com/csdaw/ggprism/blob/0e411f4f186346d13834ed2d5187355cf549cbd8/R/theme_prism.R#L173
The template comes from a file saved to the disk. Because it is loaded from the disk, its contents are never run through the theme()
function that would catch and handle the deprecated arguments.
Saving ggplot objects to disk, or parts thereof, is not recommended, precisely because of potential incompatibilities of internals like this. #25 would fix this, but I haven't heard from the maintainer since last year.
In the meanwhile, might I suggest the following workaround described here and here. It basically boils down to removing the offending elements manually from the theme:
library(ggplot2)
library(ggprism)
p <- ggplot(mpg, aes(displ, hwy)) +
geom_point() +
theme_prism()
p
#> Error in `plot_theme()`:
#> ! The `legend.text.align` theme element is not defined in the element
#> hierarchy.
p$theme[c("legend.text.align", "legend.title.align")] <- NULL
p
Created on 2024-03-12 with reprex v2.1.0
This has been resolved in the latest ggprism CRAN version 1.0.5 :)
Thank you for getting this package to work again!
And thanks for all your work helping package maintainers fix their packages!
Hi, I've got this error when I updated the ggplot2 to the latest version 3.4.4.9000.
The
legend.text.aligntheme element is not defined in the element hierarchy.
I think it has something to do with ggplot2 deprecating the
legend.text.align
argument oftheme()
.Thanks!