Section 24 Two or More Continuous Variables: Scatterplot Marix

The function ggpairs of the package GGally creates a matrix of scatterplot of numeric variables as well as boxplot of numeric and factor variables.

24.1 Scatter Plot Matrix

data(mtcars)

library(GGally)

g <- ggpairs(iris, aes(colour = Species, alpha = 0.4),
             title='Scatter plot matrix',
             columnLabels=c('Sepal Length',
                        'Sepal Width',
                        'Petal Length',
                        'Petal.Width',
                        'Species'))
g + theme_bw()

24.2 More Scatter Plot Matrix

Draw a scatter plot matrix of the first four columns of mtcars data. You may include the colour aesthetics to differentiate between cyl. Note that the the cyl variable must be a categorical variable for setting the aesthetics of this variable to colour.