ggplot2 中的 ecdf 绘图错误:未知颜色名称

ecdf plot error in ggplot2: unknown color name

我在 ggplot 中使用非常简单的 ecdf 图时出错。颜色名称错误。

    library(ggplot2)

ggplot(iris) +
  stat_ecdf(aes(x = Sepal.Length,
                col = Species),
            geom = "point")


Error: Unknown colour name: setosa

Setosa 是 Species 字段的值。代码似乎将 Species 的内容解释为这些条目的文字颜色。似乎在您的代码或会话中的某处 scale_colour_identity() 已被激活。

编辑:

我 运行 您的代码与您提供的完全一样,它运行良好并产生预期的结果,预期的行为是为三个物种分配三种默认颜色。 因此,问题肯定出在您未包含在 post.

中的某些内容中

有时没有明显原因发生在我身上,但我解决了它只是强迫物种成为因子。

试试这个:

        library(ggplot2)

ggplot(iris) +
  stat_ecdf(aes(x = Sepal.Length,
                col = as.factor(Species)),
            geom = "point")