【问题标题】:I want to change the color of ggplot bar charts我想改变ggplot条形图的颜色
【发布时间】:2018-11-10 23:11:34
【问题描述】:

我想使用 scale_color_manual 函数手动更改 ggplot 条形图的颜色。代码如下:

library(ggplot2)
ggplot(UM.Leads, aes(Leads, Count, fill = Model)) + 
  geom_bar(stat = "identity") + 
  xlab("Electrode Model") + 
  ylab("DBS Leads") + 
  ggtitle("University of Minnesota") +
  scale_color_manual(values = c("darkgoldenrod1", "grey55", "dodgerblue1")) + 
  theme_classic()

我似乎无法从 ggplot 提供的默认粉色、绿色和蓝色更改条形图的填充。任何帮助将不胜感激!

在此处查看情节:http://rpubs.com/Gopher16/393415

【问题讨论】:

  • 您已将数据映射到fill,但为color 设置了比例。试试scale_fill_manual(...)

标签: r ggplot2 colors


【解决方案1】:

为了说明@Jack Brookes 的评论并创建一个可重现的示例:

library(ggplot2)
df <- data.frame(
  gp = factor(rep(letters[1:3], each = 10)),
  y = rnorm(30)
)
ggplot(df, aes(gp, y, fill=gp)) + 
  geom_bar(stat = "identity") +
  scale_fill_manual(values = c("darkgoldenrod1", "grey55", "dodgerblue1")) + 
  theme_classic()

【讨论】:

    猜你喜欢
    • 2021-07-16
    • 1970-01-01
    • 2020-08-01
    • 2018-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-05
    • 2023-03-16
    相关资源
    最近更新 更多