% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/corrgram_grid.R
\name{corrgram2}
\alias{corrgram2}
\alias{grid_panel.conf}
\alias{grid_panel.ellipse}
\alias{grid_panel.fill}
\alias{grid_panel.pie}
\alias{grid_panel.pts}
\alias{grid_panel.shade}
\alias{grid_text.panel}
\title{Draw a correlogram using `grid` graphics}
\usage{
corrgram2(
  x,
  type = NULL,
  order = FALSE,
  labels,
  panel = grid_panel.shade,
  ...,
  lower.panel = panel,
  upper.panel = panel,
  diag.panel = NULL,
  text.panel = grid_text.panel,
  label.pos = c(0.5, 0.5),
  label.srt = 0,
  cex.labels = "fit",
  dir = "left",
  legend = FALSE,
  col.regions = colorRampPalette(c("red", "salmon", "white", "royalblue", "navy")),
  cor.method = "pearson",
  title = NULL,
  abs = FALSE
)
}
\arguments{
\item{x}{A data frame or matrix with one observation per row, or a
correlation matrix.}

\item{type}{Use 'data' or 'cor'/'corr' to explicitly specify whether
`x` is raw data or a correlation matrix. Usually this is inferred.}

\item{order}{Should variables be reordered? Use `FALSE` for no reordering,
`TRUE` or `"PC"` for PCA-based angular ordering, or `"seriation"` for
optimal seriation via the `cba` package.}

\item{labels}{Labels to use on the diagonal instead of column names.}

\item{panel}{Default panel function used for both `lower.panel` and
`upper.panel`.}

\item{...}{Additional arguments passed to the panel functions.}

\item{lower.panel, upper.panel}{Separate panel functions used below and above
the diagonal.}

\item{diag.panel}{Optional panel function used on the diagonal before drawing
diagonal labels.}

\item{text.panel}{Included for API compatibility with [corrgram()]. Diagonal
labels are currently drawn with [grid_text.panel()].}

\item{label.pos}{Horizontal and vertical placement of the diagonal label.}

\item{label.srt}{Rotation for diagonal labels.}

\item{cex.labels}{Label size for diagonal labels. Use `"fit"` to size labels
to the panel width.}

\item{dir}{Direction of the main diagonal. Use `"left"` or `"\\"` for a
descending diagonal, and `"right"` or `"/"` for an ascending diagonal.}

\item{legend}{If `TRUE`, draw a legend for the color scale.}

\item{col.regions}{A function returning a vector of colors.}

\item{cor.method}{Correlation method passed to panel functions. Default is
`"pearson"`.}

\item{title}{Optional title drawn above the correlogram.}

\item{abs}{Logical; if `TRUE`, use absolute correlations for variable
reordering.}
}
\value{
Invisibly returns `NULL`.
}
\description{
`corrgram2()` produces a correlogram using grid graphics. The off-diagonal cells
can be shaded or filled with custom panel functions to show the correlation
structure of a data matrix or correlation matrix.
}
\details{
This function is a grid-graphics variant of [corrgram()]. It accepts either a
data matrix/data frame with one observation per row or a correlation matrix.
When raw data are supplied, correlations are computed with
`use = "pairwise.complete.obs"`.

Variable reordering can be used to improve the display by placing related
variables near each other. `order = TRUE` and `order = "PC"` use the
PCA-based angular ordering described by Friendly (2002). `order =
"seriation"` uses `cba::seriation(..., method = "Optimal")` and requires the
`cba` package.
}
\examples{
# Draw a grid-based correlogram from data
vars6 <- setdiff(colnames(auto), c("Model", "Origin"))
corrgram2(auto[vars6], order = TRUE,
    lower.panel = grid_panel.shade,
    upper.panel = grid_panel.pie)

# 'vote' is a correlation matrix
corrgram2(vote, order = TRUE, upper.panel = grid_panel.conf)

}
\references{
Friendly, Michael. 2002. Corrgrams: Exploratory Displays for Correlation
Matrices. *The American Statistician*, 56, 316--324.
\url{http://datavis.ca/papers/corrgram.pdf}

D. J. Murdoch and E. D. Chow. 1996. A Graphical Display of Large Correlation
Matrices. The American Statistician, 50, 178-180.
}
\keyword{hplot}
