0

我正在尝试使用geom_mark_ellipsefrom ggforcepackage 来循环我的数据的特定子集。虽然我的数据的一个维度是数字,但另一个是分类维度,当尝试添加单个椭圆时geom_mark_ellipse,会为分类维度的每个适用值绘制两个椭圆。这听起来可能比现在更复杂,所以这里有一个简单的例子:

library(tidyverse)
library(ggforce)

set.seed(20)
my_data <- tibble(x = rnorm(20, 7, 5),
                  y = factor(rep(c("a", "b", "c", "d"), 5), ordered = TRUE),
                  z = rnorm(20, 10, 2))

ggplot(my_data, aes(x, y, size = z)) +
    geom_point() +
    geom_mark_ellipse(size = 1, aes(filter = ((y %in% c("c", "d")) & (x > 6) ))) +
    ggtitle("geom_ellipse with factor on y-axis")

这会产生以下图表: y 轴上的因子 -> 两个椭圆

虽然我想得到这样的图表:

set.seed(20)
my_data2 <- tibble(x = rnorm(20, 7, 5),
                  y = rep(c(1,2,3,4), 5),
                  z = rnorm(20, 10, 2))

ggplot(my_data2, aes(x, y, size = z)) +
    geom_point() +
    geom_mark_ellipse(size = 1, aes(filter = ((y %in% c(3, 4)) & (x > 6) ))) +
    ggtitle("geom_ellipse with numerical on y-axis")

所有数字维度 -> 一个椭圆

当然,一种解决方法是将因素强制转换为数字 - 仍然:有没有办法“告诉”geom_mark_ellipse跨越因素水平(或其他类型的分类变量值)或者这种行为是预期的功能?

4

0 回答 0