【问题标题】:Color of histogram in ggplot2ggplot2中直方图的颜色
【发布时间】:2015-07-24 19:32:02
【问题描述】:

我正在以下列方式绘制数据框的直方图,但我想将颜色设为蓝色/其他颜色。但是当我输入color = "blue" 时,它不会改变颜色并在旁边添加额外的组。

> str(neg.all.frame)
'data.frame':   455634 obs. of  2 variables:
 $ probability: num  0.645 0.536 0.365 0.523 0.587 ...
 $ group      : chr  "Unknown/Negative" "Unknown/Negative" "Unknown/Negative" "Unknown/Negative" ...

ggplot(neg.all.frame, aes(colour = "blue", probability, fill = group)) + geom_histogram(alpha = 0.2) +
  xlab("Probability of Being Interested in Fashion") + ylab("Number of People")

我该如何解决?

【问题讨论】:

  • 要将所有内容绘制为蓝色,只需将colour="blue" 移出aes() 并移入geom_histogram+ geom_histogram(colour = "blue" ...)

标签: r ggplot2 histogram


【解决方案1】:

您将字符串 "blue" 作为美学映射传递。您需要做的是使用fill=blue 作为geom_histogram 中的参数。试试这个:

ggplot(neg.all.frame, aes(probability, fill = group)) +    
 geom_histogram(alpha = 0.2, fill = "blue") + 
 xlab("Probability of Being Interested in Fashion") + 
 ylab("Number of People")

在图形语法中,美学映射将数据映射到可视化的美学特征。您要做的不是映射,而是颜色的静态变化。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-27
    • 1970-01-01
    • 2012-04-18
    • 2017-04-26
    • 2012-08-22
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    相关资源
    最近更新 更多