Theory, Examples & Exercises
Author: Francois Gillet
Draws advanced pairplot (see example below). Based on the base function
pairs, with original code written by R-code members and panel functions added by Francois Gillet.
To define the function, source the
panelutils.r file from Numerical Ecology with R book:
Example of use (using environmental data from the dataset Vegetation of Carpathian wetlands, after removing the 15th variable which is slope and not water chemistry):
source ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/scripts/NumEcolR2/panelutils.R') chem <- read.delim ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/data/chemistry.txt', row.names = 1) # reads the ''chem'' dataset pairs(chem[,-15], lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=panel.hist)
Panels in the upper triangle = correlation coefficients with results of significance testing (displayed by the number of stars), red for positive and blue for negative relationships, values in bold are significant at least at P < 0.05). Panels on diagonal = histograms of distribution. Panels on lower triangle = scatterplot with loess smoother curve.
Most of the variables need to be log-transformed (they have heavily right-skewed distribution); after the log-transformation, the result looks like this:
chem_t <- chem chem_t[, 1:12] <- log (chem[, 1:12]) pairs(chem_t[,-15], lower.panel=panel.smooth, upper.panel=panel.cor, diag.panel=panel.hist)
Note that the package
car contains the function
scatterplotMatrix, which is doing something similar (and perhaps could be also further customized).