I am new to R and ggplot2. I am using the College dataset found in the ISLR package. When I make a histogram plot and fill it with aes(fill=Private), I get the following plot.
This plot is highly misleading, because if I create a table of Private I get
No Yes
212 565
but the histogram created from ggplot2 can be interpreted as having more "No" than "Yes".
The reference course has the following figure, which correctly depicts the number of "Yes" and "No", but according to the creator of the histogram, it was generated with an older version of ggplot2. Note, I see the difference in statistics, but this does not not take away from the objective of this post.
The question is how to generate this histogram to produce a plot that depicts the proper "Yes" and "No" as see in the second histogram with the new version of ggplot2?
I have look at several other SO posts such asfor stacks,more stacks,for barplots, here, and from ggplot2, but I have not seen an answer for histograms. I have tried using arrange with the dplyr package ans well as the R order function, but to no avail.
Here is my R code
library(ISLR)
library(ggplot2)
library(dplyr)
df<-College
ggplot(df,aes(F.Undergrad))+geom_histogram(aes(fill=Private),bins = 50,color='black',alpha=0.5)+theme_bw()