The motivation for this plot is the function:
Basically a plot of a two dimensional density estimator. In the following I want
to reproduce the features with
To have some data I draw some random numbers from a two dimensional normal distribution:
smoothScatter is basically a scatter plot with a two dimensional
density estimation. This is nice especially in the case of a lot of
observations and for outlier detection.
smoothScatter in ggplot2
OK, very pretty, lets reproduce this feature in ggplot2. First thing is to add
the necessary layers, which I already mentioned is a two dimensional density
estimation, combined with the
geom called ‘tile’. Also I use the fill
aesthetic to add colour and a different palette:
I add one additional layer; a simple scatter plot. To make the points
transparent I choose alpha to be
1/10 which is a relative quantity with
respect to the number of observations.
A similar approach is also discussed on
Actually that version is closer to
Changing the theme
The last step is to tweak the theme-elements. Not that the following adds to
any form of information but it looks nice. Starting from a standard theme,
theme_classic, which is close to where I want to get, I get rid of all labels,
axis and the legend.
The last thing is to save the plot in the correct format for display:
And that’s it, a nice picture which used to be a statistical graph.