- R Data Visualization Recipes
- Vitor Bianchi Lanzetta
- 81字
- 2021-07-02 23:33:28
How to do it...
- Draw a ggplot2 scatterplot like this:
library(ggplot2)
base_p <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width, colour = Species))
scatter <- base_p + geom_point( alpha = .5, aes(shape = Species)) +
geom_rug(alpha = .5, sides = 'tr', show.legend = F) +
theme(legend.position = 'bottom')
- Load ggExtra and input the ggplot object into ggMarginal() function:
library(ggExtra)
ggMarginal(scatter, iris, type = 'histogram', bins = 150)
The result is shown by figure 2.9:

Figure 2.9 - Marginal histograms by the scatterplots.