Last data update: 2014.03.03

R: More panel plots
panelsR Documentation

More panel plots

Description

Several panel plots that can be used with functions like coplot and pairs.

Usage

panel.reg(x, y, col = par("col"), bg = par("bg"), pch = par("pch"),
    cex = par("cex"), lwd = par("lwd"), line.reg = lm, line.col = "red",
    line.lwd = lwd, untf = TRUE, ...)
panel.ellipse(x, y, col = par("col"), bg = par("bg"), pch = par("pch"),
    cex = par("cex"), el.level = 0.7, el.col = "cornsilk", el.border = "red",
    major = TRUE, ...)
panel.cor(x, y, use = "everything", method = c("pearson", "kendall", "spearman"),
    alternative = c("two.sided", "less", "greater"), digits = 2, prefix = "",
    cex = par("cex"), cor.cex = cex, stars.col = "red", ...)

Arguments

x

a numeric vector.

y

a numeric vector of same length as x

col

the color of the points.

bg

the background color for symbol used for the points.

pch

the symbol used for the points.

cex

the expansion factor used for the points.

lwd

the line width.

line.reg

a function that calculates coefficients of a straight line, for instance, lm, or rlm for robust linear regression.

line.col

the color of the line.

line.lwd

the width of the line.

untf

logical asking whether to untransform the straight line in case one or both axis are in log scale.

el.level

the confidence level for the bivariate normal ellipse around data; the default value of 0.7 draws an ellipse of roughly +/-1 sd.

el.col

the color used to fill the ellipse.

el.border

the color used to draw the border of the ellipse and the standardized major axis.

major

if TRUE, the standardized major axis is also drawn.

use

one of "everything", "all.obs", "complete.obs", "na.or.complete", or "pairwise.complete.obs" (can be abbreviated). Defines how the cor() function behaves with missing observations.

method

one of the three correlation coefficients "pearson", (default), "kendall", or "spearman" (can be abbreviated).

alternative

the alternative hypothesis in correlation test, see cor.test.

digits

the number of decimal digits to print when the correlation coefficient is printed in the graph.

prefix

a prefix (character string) to use before the correlation coefficient printed in the graph.

cor.cex

expansion coefficient for text in printing correlation coefficients.

stars.col

the color used for significance stars (with: *** p < 0.001, ** p < 0.1, * p < 0.05, . p < 0.1.

...

further arguments to plot functions.

Details

Theses functions should be used outside of the diagonal in pairs(), or with coplot(), as they are bivariate plots.

Value

These functions return nothing and are used for their side effect of plotting in panels of composite plots.

Author(s)

Philippe Grosjean <phgrosjean@sciviews.org>, but code inspired from panel.smooth() in graphics and panel.car() in package car.

See Also

coplot, pairs, panel.smooth, lm, ellipse, cor and cor.test

Examples

## Smooth lines in lower graphs and straight lines in upper graphs
pairs(trees, lower.panel = panel.smooth, upper.panel = panel.reg)
## Robust regression lines
require(MASS)  # For rlm()
pairs(trees, panel = panel.reg, diag.panel = panel.boxplot,
    reg.line = rlm, line.col = "blue", line.lwd = 2)
## A Double log graph
pairs(trees, lower.panel = panel.smooth, upper.panel = panel.reg, log = "xy")

## Graph suitables to explore correlations (take care that there are potentially
## many simultaneous tests done here... So, you loose much power is the whole
## analysis... use it just as an indication, nothing more!)
## Pearson's r
pairs(trees, lower.panel = panel.ellipse, upper.panel = panel.cor)
## Spearman's rho (ellipse and straight lines not suitable here!)
pairs(trees, lower.panel = panel.smooth, upper.panel = panel.cor,
    method = "spearman", span = 1)
## Several groups (visualize how bad it is to consider the whole set at once!)
pairs(iris[, -5], lower.panel = panel.smooth, upper.panel = panel.cor,
    method = "kendall", span = 1, col = c("red3", "blue3", "green3")[iris$Species])
## Now analyze correlation for one species only
pairs(iris[iris$Species == "virginica", -5], lower.panel = panel.ellipse,
    upper.panel = panel.cor)
    
## A coplot with custom panes
coplot(Petal.Length ~ Sepal.Length | Species, data = iris, panel = panel.ellipse)

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SciViews)
Loading required package: MASS
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/SciViews/panels.Rd_%03d_medium.png", width=480, height=480)
> ### Name: panels
> ### Title: More panel plots
> ### Aliases: panel.reg panel.ellipse panel.cor
> ### Keywords: aplot
> 
> ### ** Examples
> 
> ## Smooth lines in lower graphs and straight lines in upper graphs
> pairs(trees, lower.panel = panel.smooth, upper.panel = panel.reg)
> ## Robust regression lines
> require(MASS)  # For rlm()
> pairs(trees, panel = panel.reg, diag.panel = panel.boxplot,
+     reg.line = rlm, line.col = "blue", line.lwd = 2)
There were 50 or more warnings (use warnings() to see the first 50)
> ## A Double log graph
> pairs(trees, lower.panel = panel.smooth, upper.panel = panel.reg, log = "xy")
> 
> ## Graph suitables to explore correlations (take care that there are potentially
> ## many simultaneous tests done here... So, you loose much power is the whole
> ## analysis... use it just as an indication, nothing more!)
> ## Pearson's r
> pairs(trees, lower.panel = panel.ellipse, upper.panel = panel.cor)
> ## Spearman's rho (ellipse and straight lines not suitable here!)
> pairs(trees, lower.panel = panel.smooth, upper.panel = panel.cor,
+     method = "spearman", span = 1)
There were 50 or more warnings (use warnings() to see the first 50)
> ## Several groups (visualize how bad it is to consider the whole set at once!)
> pairs(iris[, -5], lower.panel = panel.smooth, upper.panel = panel.cor,
+     method = "kendall", span = 1, col = c("red3", "blue3", "green3")[iris$Species])
There were 50 or more warnings (use warnings() to see the first 50)
> ## Now analyze correlation for one species only
> pairs(iris[iris$Species == "virginica", -5], lower.panel = panel.ellipse,
+     upper.panel = panel.cor)
>     
> ## A coplot with custom panes
> coplot(Petal.Length ~ Sepal.Length | Species, data = iris, panel = panel.ellipse)
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>