麻烦着色直方图

Trouble coloring histogram

我目前正在尝试使用 'ggplot2' 为直方图上的一系列值着色。对于这个例子,我将使用“钻石”数据集。

当我执行以下命令时:

qplot(carat, data=diamonds,geom="histogram", binwidth=0.01, fill=..count..) 
+ scale_fill_continuous(low="#F79420", high="#F79420", limits=c(1000,3000))

我得到以下正确的情节:

但是当我使用具有等效代码的另一种语法时,我无法得到相同的结果。代码:

ggplot(diamonds, aes(x = carat)) + 
geom_histogram(
    binwidth = 0.01,
    fill=aes(y = ..count..)
    ) +
scale_fill_continuous(low="#F79420", high="#F79420", limits=c(1000,3000))

结果:

你能告诉我我做错了什么吗?

谢谢。

试试这个:

 ggplot(diamonds, aes(x = carat)) + 
  geom_histogram(
     binwidth = 0.01,
     aes(fill = ..count..)
   ) +
   scale_fill_continuous(low="#F79420", high="#F79420", limits=c(1000,3000))

这将为您提供与上面第一张相同的图片。