Closed ppm1337 closed 1 month ago
By setting fill=NA
you are dropping or removing the grouping by color
for the text layer. To still dodge the labels you have to set the group
aes, i..e add group=color
.
library(ggplot2)
library(ggtext)
diamonds_subset <- diamonds[diamonds$cut == "Fair", ][1:10, ]
base_plot <- diamonds_subset |>
ggplot(
aes(
x = cut,
y = carat,
fill = color
)
) +
geom_bar(
stat = "identity",
position = position_dodge(width = 0.9)
)
base_plot +
geom_richtext(
aes(label = clarity, group = color),
position = position_dodge(width = 0.9),
fill = NA, label.color = NA
)
Created on 2023-06-17 with reprex v2.0.2
Hey,
Thanks for this amazing package. I have an issue removing the fill color from the label boxes created by
geom_richtext
. As suggested in the documentation, this can be achieved by settingfill = NA
, but doing so breaks the positioning of the labels if positiondodge
is specified.The reprex code produces the following two plots:
As you can see, the second plot does not retain the position information.
Truncated
sessionInfo()
: