Reputation: 484
I'm currently trying to color a range of values on a histogram using 'ggplot2'. For this example I’ll use the ‘diamonds’ dataset.
when I execute the follow comand:
qplot(carat, data=diamonds,geom="histogram", binwidth=0.01, fill=..count..)
+ scale_fill_continuous(low="#F79420", high="#F79420", limits=c(1000,3000))
I get thw following and correct plot:
But when I use another syntax with equivalent code, I cannot get the same result. Code:
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))
Result:
Can you please tell me what I’m doing wrong?
Thanks.
Upvotes: 0
Views: 53
Reputation: 11514
Try this:
ggplot(diamonds, aes(x = carat)) +
geom_histogram(
binwidth = 0.01,
aes(fill = ..count..)
) +
scale_fill_continuous(low="#F79420", high="#F79420", limits=c(1000,3000))
This will give you the same picture as the first one above.
Upvotes: 1