Steve Haroz@steveharoz.com·2023-10-10T16:59:37.111Z#
Got a simple version working. No warnings or messages!
ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +
geom_label(aes(colour = factor(cyl), linecolour = factor(cyl))) +
scale_color_manual(values = c("red", "green", "blue"), aesthetics = c("colour", "linecolour"))
Brenton Wiernik@bwiernik.bsky.social·2023-10-10T16:59:56.513Z#
Amazing!
Brenton Wiernik@bwiernik.bsky.social·2023-10-10T17:02:14.493Z#
Does it work to set different color scales for color and linecolor?
scale_color_manual(values = c(“red”, “blue”, “green”), aesthetics = “color”) +
scale_color_manual(values = c(“black”, “white”), aesthetics = “linecolor”)
Matthew Kay@mjskay.com·2023-10-13T05:15:17.172Z#
Try it with a continuous color scale (i.e. one that uses guide_colorbar not guide_legend). It should give the error "Guide `colorbar` cannot be used for linecolour" because colorbar hardcodes the aesthetics it is allowed to be used for, which makes it annoying to use with extension packages.
Brenton Wiernik@bwiernik.bsky.social·2023-10-13T11:04:50.177Z#
That detection should probably use a regex like /(colou?r)|(fill)/
Matthew Kay@mjskay.com·2023-10-13T15:10:20.343Z#
Yeah I've been meaning to file a bug or pr for... several years? Hah. Anyway I'm teaching a new class this quarter so there's already a bunch of ggdist issues on my plate that won't get touched for some time.
Steve Haroz@steveharoz.com·2023-10-13T13:51:18.498Z#
New approach:
scale_colorfill_viridis = reuse_scale(scale_color_viridis_c, c("color", "fill"))
ggplot(mtcars) +
aes(wt, mpg, color=hp, fill=hp) +
geom_point(shape=25, size=3, stroke=2) +
scale_colorfill_viridis()
Replace c("color", "fill") with any one or more color-based aesthetics you want.
Steve Haroz@steveharoz.com·2023-10-13T13:55:13.854Z#
I tested it by replacing all fill scales in the ggplot2 source with one-line calls to reuse_scale(scale_whatever_colour, "fill"). And it worked!
And that includes the default logic in scale_fill_continuous which determines what to do when the scale is unspecified. Everything is copied from colour.
Matthew Kay@mjskay.com·2023-10-13T15:22:22.117Z#
I like this factory approach, but this wasn't the problem I meant - try mapping a continuous variable to the linecolor aesthetic. You should get an error in creating legend.