我试图在直方图中可视化来自 ggplot2 的钻石数据,其中显示克拉的分布。
我尝试将 aes 值从 ggplot 移动到 geom_histogram(),尝试 ..fill..,并以不同的方式操作代码,但结果是相同的。
histogram<- ggplot(diamonds, aes(x=carat, fill=carat)) +
geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')
Run Code Online (Sandbox Code Playgroud)
随着克拉的增加,我希望看到我的直方图从蓝色变为黄色,但我仍然看到它是灰色的。
尝试使用fill=..x..:
ggplot(diamonds, aes(x=carat, fill=..x..)) +
geom_histogram(binwidth = 0.1) + scale_fill_gradient(low='blue', high='yellow')
Run Code Online (Sandbox Code Playgroud)