【问题标题】:Ggplot2: how to manually assign different colors to different factor levels? [duplicate]ggplot2:如何手动为不同的因子级别分配不同的颜色? [复制]
【发布时间】:2020-07-25 11:38:09
【问题描述】:

我的因素有 2 个等级:A 和 B

data_set %>% 
    ggplot(aes(x = effort, y = rating, fill = factorAB)) + 
    geom_bar(position = "dodge", stat = "summary", fun.y = "mean") + 
    scale_fill_manual(name = "factorAB", values=c("darkgoldenrod2", "chartreuse4")) 

所以我的 X 轴上有 2 个条件(2 个努力条件,努力 1 和努力 2),我也有 2 个因素(A 和 B)。 Scale_fill_manual 函数为每个因子分配颜色,A 为 1 种颜色,B 为 1 种颜色,但我想分配 4 种不同的颜色(因此努力 1 A 与努力 2 A 不同)。

我该怎么做?谢谢。

【问题讨论】:

  • 请使用dput(mydata)提供数据

标签: r ggplot2 colors fill


【解决方案1】:

将填充更改为交互!

 ggplot(aes(x = effort, y = rating, fill = interaction(factorAB,effort)))
+ ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-09-29
    • 2012-01-25
    • 1970-01-01
    • 2017-04-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-03
    • 1970-01-01
    相关资源
    最近更新 更多