Created
July 30, 2022 13:46
-
-
Save luisDVA/0fb7dea571a1bc8416d7df6a74a323ac to your computer and use it in GitHub Desktop.
can't seem to change fill color in geom_point_svg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggsvg) | |
library(ggplot2) | |
# the svg that I need to use | |
svg_url <- "https://raw.githubusercontent.com/luisDVA/luisdva.github.io/master/assets/images/Cat-green.svg" | |
cat_svg <- paste(readLines(svg_url), collapse = "\n") | |
# toy data | |
dat <- | |
expand.grid(y=1:2,x=seq_len(2)) | |
dat$qual <- letters[1:4] | |
dat | |
# works and uses default colors | |
ggplot(dat)+ | |
geom_point_svg(aes(x, y,css(selector = "path:nth-child(1)", fill = qual)), svg = cat_svg) + | |
scale_svg_default() | |
# all colors are unchanged | |
ggplot(dat)+ | |
geom_point_svg(aes(x, y,css(selector = "path:nth-child(1)", fill = qual)), svg = cat_svg) + | |
scale_svg_fill_viridis_d(aesthetics="fill") | |
# colors unchanged | |
ggplot(dat)+ | |
geom_point_svg(aes(x, y,css(selector = "path:nth-child(1)", fill = qual)), svg = cat_svg) + | |
scale_svg_fill_viridis_d("path:nth-child(1)") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try:
Explanation: The name of the aesthetic to the scale argument must match the aesthetic in the geom() call exactly.