改变叠加直方图R的位置

改变叠加直方图R的位置,r,plot,histogram,data-visualization,R,Plot,Histogram,Data Visualization,我使用了以下代码: ggplot(adult, aes(age)) + geom_histogram(aes(fill= income), color= 'black', binwidth = 1) + theme_bw() 要生成此绘图,请执行以下操作: 我的问题是,如何更改绘图的堆叠位置,使其如下所示: 在绘图之前,您只需更改收入变量的因子水平顺序即可 #重新排序填充变量 成人$收入 #plot library(ggplot2) ggplot(adult, aes(age)) +

我使用了以下代码:

ggplot(adult, aes(age)) + geom_histogram(aes(fill= income), color= 'black', binwidth = 1) + theme_bw()
要生成此绘图,请执行以下操作:

我的问题是,如何更改绘图的堆叠位置,使其如下所示:


在绘图之前,您只需更改
收入
变量的因子水平顺序即可

#重新排序填充变量
成人$收入
#plot
library(ggplot2)
ggplot(adult, aes(age)) + 
  geom_histogram(aes(fill= income), color= 'black', binwidth = 1) + 
  theme_bw()