Rug the margins using geom_rug()
Up till now, the chapter has focused on how to draw scatterplots and solutions related to over-plotting. Upcoming recipes, including this one, shall focus on enhancing scatterplots. If there is a bivariate relation to be displayed there is also two univariate distributions to show. How can they be used to improve the plots?Â
Answer lies in filling the margins with supplemental plots carrying representations of underlying univariate distributions. Still relying on the iris data set framework, this recipe introduces a simple solution, almost restricted to ggplot2
. Let's rug plots in the margins with geom_rug()
.
How to do it...
- Draw a scatterplot using
ggplot2
and sum thegeom_rug()
layer:
> set.seed(50) ; library(ggplot2) > rug <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species)) > rug <- rug + geom_jitter(aes( shape = Species), alpha = .4) + geom_rug(position...