I am learning R and I am trying to create a composite histogram that will contain the histograms of three groups, as defined by the values of the column 'cluster' in the dataframe.
The data look like this:
TOTAL_Estimated_Collateral_value_sum cluster
1 -0.17499342 1
2 -0.86443362 1
3 0.22211949 2
4 0.01007717 1
5 -0.77617685 2
6 -1.43518056 1
7 -0.19705983 1
8 -0.39170108 1
9 -0.94073376 1
10 1.20525601 2
TOTAL_Estimated_Collateral_value_sum cluster
Min. :-1.7697 Min. :1.000
1st Qu.:-0.7626 1st Qu.:1.000
Median :-0.1322 Median :1.000
Mean : 0.0000 Mean :1.329
3rd Qu.: 0.8459 3rd Qu.:2.000
Max. : 1.8782 Max. :3.000
> table(df_all$cluster)
1 2 3
24342 8565 1350
The code I am using is the following:
ggplot(df_all, aes(x=TOTAL_Estimated_Collateral_value_sum, color=cluster)) +
geom_histogram(alpha = 0.7, position="dodge")
The image I get is the following:
As you can see, the observations are not coloured by the value of the cluster as I would expect.
Could you please explain to me why this is the case and what I should do to fix my code and get the expected output?