====== pairs (with panel functions) ======
**Author: Francois Gillet**
Draws an advanced pairplot (see example below). Based on the base function ''pairs'', with original code written by R-core members and panel functions added by Francois Gillet.
To define the function, source the ''panelutils.r'' file from the book //Numerical Ecology with R//:
source ('https://raw.githubusercontent.com/zdealveindy/anadat-r/master/scripts/NumEcolR2/panelutils.R')
Example of use (using environmental data from the dataset [[en:data:wetlands|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)
{{:obrazky:pairs_chem_1.png?direct|}}
Panels in the upper-right triangle list correlation coefficients and their significance (displayed by the number of stars), where red indicates positive relationships and blue indicates negative relationships; values in bold are significant at P < 0.05. Panels on the diagonal include the names of variables and histograms of value distribution. Panels on the lower-left triangle show scatterplots with a loess smoother curve.
Most of the variables need to be log-transformed (they have a 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)
{{:obrazky:pairs_chem_2.png?direct|}}
//**Note:** Consider using function ''ggpairs'' from the package ''GGally'' (much fancier ggplot2 version of ''pairs'' function). There exists also an older package ''car'' that contains the function ''scatterplotMatrix'', which behaves similarly to ''pairs'' (but is rather outdated).//