【问题标题】:How do I add color to individual geom points?如何为单个几何点添加颜色?
【发布时间】:2023-01-01 02:37:39
【问题描述】:

当前代码:
ggplot(compare, aes(x=specificity, y=false_positives)) + 
  geom_jitter(height=.02, color=specificity) +
  scale_discrete_manual(values=c("#999999", "#E69F00", "#56B4E9", "violet"))

manual_scale(美学,价值观,休息,...)中的错误: 缺少参数“美学”,没有默认值

【问题讨论】:

  • 如果我们有数据,我们可以检查它是否是 geom_jitter 中缺少的 aes 调用。
  • 你想要地图颜色值aesthetic,所以你必须这样告诉 ggplot:geom_jitter(aes(color = specifity), ...)

标签: r ggplot2 geom-point scale-color-manual


【解决方案1】:

是这样的吗?

library(tidyverse)

ggplot(df, aes(x=specificity, y=false_positives, color= factor(specificity))) +
  geom_point(position = position_jitter()) +
  scale_color_manual(values=c("#999999", "#E69F00", "#56B4E9", "#8800FF")) +
  theme_bw()

数据:

df <- structure(list(specificity = c(0.9, 0.87, 0.89, 0.91), false_positives = c(0.4, 
0.3, 0.4, 0.4)), row.names = c("Logistic", "Probit", "KNN", "Naive"
), class = "data.frame")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-13
    • 1970-01-01
    • 2012-11-29
    • 2021-08-15
    • 2011-06-06
    • 1970-01-01
    相关资源
    最近更新 更多