R 堆叠直方图的代码

R 堆叠直方图的代码,r,ggplot2,histogram,R,Ggplot2,Histogram,我试图创建钻石价格的柱状图,显示切割钻石的比例。就我所知: ggplot(aes(x = price), data = diamonds_df) + geom_histogram(binwidth = 0.1, fill = "white", colour = "black") + facet_wrap(~color, scales = "free_y") + scale_x_log10() + ylab("Total Count") + xlab("Diamond Price") + ggt

我试图创建钻石价格的柱状图,显示切割钻石的比例。就我所知:

ggplot(aes(x = price), data = diamonds_df) +
geom_histogram(binwidth = 0.1, fill = "white", colour = "black") +
facet_wrap(~color, scales = "free_y") + 
scale_x_log10() +
ylab("Total Count") +
xlab("Diamond Price") +
ggtitle("Distribution of diamond prices for different diamond colours and cuts")
我试过使用

color = cut
而且

fill = cut

在美观的包装内,但没有任何效果。

此代码给出了我想要的情节,但看起来相当混乱

ggplot(diamonds_df, aes(price, fill=cut)) + 
geom_bar(width = 0.05) +
facet_wrap(~color, scales = "free_y") + 
scale_x_log10() +
ylab("Total Count") +
xlab("Diamond Price") +
ggtitle("Distribution of diamond prices for different diamond colours and cuts")

使用
geom_直方图
并指定更大的
binwidth