The question is about two observations related to following 3 figures:
(1) Why the histograms in (a) and (b) are different if number of bins is same?
(2) Histogram in (b) is exactly same as the histogram for the fillnonsmo
. If this is the case then how to make histogram of complete data using ggplot()?
(a) Plot using hist(chol$AGE,30)
.
(b) Histogram plotted with ggplot(data=chol, aes(chol$AGE)) + geom_histogram()
and default values i.e. 30 bins.
(c) Now adding fill with respect to the variable SMOKE
:
ggplot(data=chol, aes(chol$AGE)) +
geom_histogram(aes(fill = chol$SMOKE))
ggplot(data=chol, ...)
, you should never usechol$
in your aesthetics or anywhere else in any of the ggplot verbs (unless you are providing a different subset on the data, eitherdata=
orsubset=
. It is never needed, often problematic. It should be justggplot(data, aes(AGE)) + ...
. – r2evans