首页 > 解决方案 > 如何使用填充颜色为 ggforce::geom_mark_ellipse 标签着色

问题描述

目前是否可以使用彩色生成标签?ggforce::geom_mark_ellipse(label=)

在下面的示例中,我希望看到绿色的杂色字体:

标签: rggplot2ggforce

解决方案


是的,但不像任何其他映射美学那样直接。您必须构建一个新图层,在其中更改颜色并正确过滤图层。如果您有 10 多个组,每个组都需要自己的标签颜色,您会发现这变得非常费力。

library(ggplot2)
library(ggforce)

ggplot(iris, aes(Petal.Length, Petal.Width)) +
  geom_mark_ellipse(aes(fill = Species, label = Species,
                        filter = Species != 'versicolor')) +
  geom_mark_ellipse(aes(fill = Species, label = Species,
                        filter = Species == 'versicolor'),
                    label.colour = "green") +
  geom_point()

在此处输入图像描述


推荐阅读