Closed wkumler closed 12 months ago
ggplot2 doesn't officially support vectorisation through the theme elements. They way one should 'vectorise' colours is through the text itself by using HTML, though that might give some order issues:
library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.3.1
library(ggtext)
#> Warning: package 'ggtext' was built under R version 4.3.1
ggplot(data.frame(x=1, y=1, facet=c("<span style = 'color:red'>1</span>",
"<span style = 'color:blue'>2</span>"))) +
geom_point(aes(x, y)) +
facet_wrap(~facet) +
theme(strip.text = element_markdown())
Created on 2023-10-06 with reprex v2.0.2
Yes theme elements aren't vectorized in ggplot. Apply colors by embedding this in HTML as part of the strip title and the using element_markdown()
I'm running into problems when I try to supply a vector of colors with
strip.text = element_markdown()
. It looks like only a single color is plotted, but I think that all of the colors are actually getting plotted on top of each other:It seems like it's overplotting rather than vectorizing because 1) there's a halo of red around the blue number visible at high magnification and 2) the order of colors in the vector determines the final color, with the last color provided becoming the one visible on "top".
Other
element_markdown
options seem to work just fine (and I expectedstrip.text
to behave similarly to others so I don't think this is expected behavior):In a very mysterious case using
facet_grid
with two coordinates, however, the labels on the right of the plot are colored using only(?) the first color provided in the vector, while the labels at top continue with the overplotting behavior described above (unless specified explicitly usingstrip.text.x
andstrip.text.y
.The conversation at https://github.com/tidyverse/ggplot2/issues/3492 implies that
element_markdown
is intended to handle vectorized text. The issue seems similar to the one raised here but I don't think this is a case of inheritance problems, and is maybe connected to the issue with fonts in R 4.2.0 even though I'm on 4.3.1? Is this expected behavior or am I doing something wrong in my calls toelement_markdown
?