「employee_attrition」というデータフレームがあります。私が興味を持っている変数は 2 つあります。1 つ目は「MonthlyIncome」(給与の連続データ) と呼ばれ、2 つ目は離散値 (1、2、3、または 4) を取る「PerformanceRating」です。私の意図は、MonthlyIncome のヒストグラムを作成し、同じプロットに PerformanceRating を表示することです。私はこれを持っています:
ggplot(data = employee_attrition, aes(x=MonthlyIncome, fill=PerformanceRating))+
geom_histogram(aes(y=..count..))+
xlab("Salario mensual (MonthlyIncome)")+
ylab("Frecuencia")+
ggtitle("Histograma: MonthlyIncome y Attrition")+
theme_minimal()
問題は、ヒストグラムの各バーに関連付けられた "PerformanceRating" がプロットに表示されないことです。
私のデータフレームは次のようなものです:
MonthlyIncome PerformanceRating
1 5993 1
2 5130 1
3 2090 4
4 2909 3
5 3468 4
6 3068 3
そして、MonthlyIncome の頻度と PerformanceRating の 4 色の各バーを示すヒストグラムが必要です。

このようなものですが、4色あります (PerformanceRating Values)