str(neg.all.frame)-6ren">
gpt4 book ai didi

r - ggplot2中直方图的颜色

转载 作者:行者123 更新时间:2023-12-04 11:08:18 28 4
gpt4 key购买 nike

我正在按以下方式绘制数据框的直方图,但我想将颜色设置为蓝色/其他任何颜色。但是当我放置 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")

enter image description here

我该如何解决?

最佳答案

您将字符串 "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")

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

关于r - ggplot2中直方图的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31618415/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com