You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's say we might want to try to adopt this in ggplot2, like so:
library(ggplot2)
ggplot(data.frame(x=1:2), aes(x, x)) +
geom_tile(aes(fill=factor(x)), width=1) +
scale_fill_manual(
values=list(grad, pat)
)
#> Error in `geom_tile()`:#> ! Problem while converting geom to grob.#> ℹ Error occurred in the 1st layer.#> Caused by error:#> ! Unknown colour name: list(x1 = 0, y1 = 0.5, x2 = 1, y2 = 0.5, stops = c(0, 1), colours = c("#DF536B", "white"), extend = "pad", group = FALSE)
As can be seen above, we currently can't use this in ggplot2. I think the only thing currently prohibiting this is the alpha() function that can't handle a list of patterns as input.
If I change the alpha() function to be like this (real solution should probably be more elegant):
alpha<-function(colour, alpha=NA) {
if (is.list(colour)) {
return(colour)
}
...# rest of function body
}
And build the package and re-load ggplot2 (which doesn't lend itself well to reprexes), I can get exactly what I might have expected:
Since R 4.2.0, the {grid} package has supported vectorised patterns. A simplified example from the link, with a list of patterns, is the code below:
Created on 2022-10-30 by the reprex package (v2.0.1)
Let's say we might want to try to adopt this in ggplot2, like so:
As can be seen above, we currently can't use this in ggplot2. I think the only thing currently prohibiting this is the
alpha()
function that can't handle a list of patterns as input.If I change the
alpha()
function to be like this (real solution should probably be more elegant):And build the package and re-load ggplot2 (which doesn't lend itself well to reprexes), I can get exactly what I might have expected:
The text was updated successfully, but these errors were encountered: