Learn R Programming

GGally (version 2.2.1)

ggfacet: Single ggplot2 plot matrix with facet_grid

Description

Single ggplot2 plot matrix with facet_grid

Usage

ggfacet(
  data,
  mapping = NULL,
  columnsX = 1:ncol(data),
  columnsY = 1:ncol(data),
  fn = ggally_points,
  ...,
  columnLabelsX = names(data[columnsX]),
  columnLabelsY = names(data[columnsY]),
  xlab = NULL,
  ylab = NULL,
  title = NULL,
  scales = "free"
)

Arguments

data

data.frame that contains all columns to be displayed. This data will be melted before being passed into the function fn

mapping

aesthetic mapping (besides x and y). See aes()

columnsX

columns to be displayed in the plot matrix

columnsY

rows to be displayed in the plot matrix

fn

function to be executed. Similar to ggpairs and ggduo, the function may either be a string identifier or a real function that wrap understands.

...

extra arguments passed directly to fn

columnLabelsX, columnLabelsY

column and row labels to display in the plot matrix

xlab, ylab, title

plot matrix labels

scales

parameter supplied to ggplot2::facet_grid. Default behavior is "free"

Examples

Run this code
# Small function to display plots only if it's interactive
p_ <- GGally::print_if_interactive
if (requireNamespace("chemometrics", quietly = TRUE)) {
  data(NIR, package = "chemometrics")
  NIR_sub <- data.frame(NIR$yGlcEtOH, NIR$xNIR[, 1:3])
  str(NIR_sub)
  x_cols <- c("X1115.0", "X1120.0", "X1125.0")
  y_cols <- c("Glucose", "Ethanol")

  # using ggduo directly
  p <- ggduo(NIR_sub, x_cols, y_cols, types = list(continuous = "points"))
  p_(p)

  # using ggfacet
  p <- ggfacet(NIR_sub, x_cols, y_cols)
  p_(p)

  # add a smoother
  p <- ggfacet(NIR_sub, x_cols, y_cols, fn = "smooth_loess")
  p_(p)
  # same output
  p <- ggfacet(NIR_sub, x_cols, y_cols, fn = ggally_smooth_loess)
  p_(p)

  # Change scales to be the same in for every row and for every column
  p <- ggfacet(NIR_sub, x_cols, y_cols, scales = "fixed")
  p_(p)
}

Run the code above in your browser using DataLab