Using geom_shadowtext() in custom function fails; missing alpha imports?
kstierhoff opened this issue · comments
Hi,
I created a function in my own package that creates a ggplot2 object with a geom_shadowtext() layer for labels. When I run the code, it fails with the following error:
Error in alpha(data$colour, data$alpha) : could not find function "alpha"
I've included shadowtext in my imports, as well as ggplot2. I also don't use alpha anywhere else in the function, but I can see from your code posted here that GeomShadowText uses ggproto, which in turn has an argument for alpha, which I presume is causing the issue. Is this an issue with imports in shadowtext? Or can you think of a workaround? I'm not immediately able to think of a minimal reproducible example, but if I do, I'll post here. Sorry about that.
Thanks,
Kevin
Thank you!
Hi,
So that error is fixed, but now I get a different error:
Error in numnotnull("fontsize") : object '.pt' not found
Below is a minimal reprex that I hope will illustrate the problem:
# Test data frame
xy_df <- data.frame(x = 1, y = 1, name = "test")
# Function using geom_text
text_ex <- function(xy_df) {
ggplot2::ggplot() +
ggplot2::geom_text(data = xy_df, ggplot2::aes(x, y, label = name))
}
# Function using geom_shadowtext
shadow_ex <- function(xy_df) {
ggplot2::ggplot() +
shadowtext::geom_shadowtext(data = xy_df, ggplot2::aes(x, y, label = name))
}
# This works
text_ex(xy_df)
# This does not
shadow_ex(xy_df)
I assume it relates to this portion of your shadowtextGrob function:
Thanks,
Kevin
fixed.
Thank-you, again! Working great now.