ggpairs {GGally}R Documentation

ggpairs - A GGplot2 Matrix

Description

Make a matrix of plots with a given data set

Usage

ggpairs(data, columns = 1:ncol(data), title = "", upper = list(),
  lower = list(), diag = list(), params = NULL, ...,
  axisLabels = "show", columnLabels = colnames(data[, columns]),
  legends = FALSE, verbose = FALSE)

Arguments

data

data set using. Can have both numerical and categorical data.

columns

which columns are used to make plots. Defaults to all columns.

title

title for the graph

upper

see Details

lower

see Details

diag

see Details

params

vector of parameters to be applied to geoms. Each value must have a corresponding name, such as c(binwidth = 0.1).

...

other parameters being supplied to geom's aes, such as color

axisLabels

either "show" to display axisLabels, "internal" for labels in the diagonal plots, or "none" for no axis labels

columnLabels

label names to be displayed. Defaults to names of columns being used.

legends

boolean to determine the printing of the legend in each plot. Not recommended.

verbose

boolean to determine the printing of "Plot #1, Plot #2...."

Details

upper and lower are lists that may contain the variables 'continuous', 'combo' and 'discrete'. Each element of the list is a string implementing the following options: continuous = exactly one of ('points', 'smooth', 'density', 'cor', 'blank'); combo = exactly one of ('box', 'dot', 'facethist', 'facetdensity', 'denstrip', 'blank'); discrete = exactly one of ('facetbar','ratio', 'blank').

diag is a list that may only contain the variables 'continuous' and 'discrete'. Each element of the diag list is a string implmenting the following options: continuous = exactly one of ('density', 'bar', 'blank'); discrete = exactly one of ('bar', 'blank').

If a list option it will be set to the function default. If 'blank' is ever chosen as an option, then ggpairs will produce a blank plot, as if nothing was printed there.

Value

ggpair object that if called, will print

Author(s)

Barret Schloerke schloerke@gmail.com, Jason Crowley crowley.jason.s@gmail.com, Di Cook dicook@iastate.edu, Heike Hofmann hofmann@iastate.edu, Hadley Wickham h.wickham@gmail.com

Examples

# plotting is reduced to the first couple of examples.
# Feel free to print the ggpair objects created in the examples

data(tips, package = "reshape")
pm <- ggpairs(tips[,1:3])
# pm
pm <- ggpairs(tips, 1:3, columnLabels = c("Total Bill", "Tip", "Sex"))
# pm
pm <- ggpairs(tips, upper = "blank")
# pm


# Custom Example
pm <- ggpairs(
  tips[,c(1,3,4,2)],
  upper = list(continuous = "density", combo = "box"),
  lower = list(continuous = "points", combo = "dot")
)
# pm

# Use sample of the diamonds data
data(diamonds, package="ggplot2")
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1],200),]

# Custom Example
pm <- ggpairs(
 diamonds.samp[,1:5],
 upper = list(continuous = "density", combo = "box"),
 lower = list(continuous = "points", combo = "dot"),
 color = "cut",
 alpha = 0.4,
 title = "Diamonds"
)
# pm

# Will plot four "Incorrect Plots"
bad_plots <- ggpairs(
  tips[,1:3],
  upper = list(continuous = "wrongType1", combo = "wrongType2"),
  lower = list(continuous = "IDK1", combo = "IDK2", discrete = "mosaic"),
)
# bad_plots

# Only Variable Labels on the diagonal (no axis labels)
pm <- ggpairs(tips[,1:3], axisLabels="internal")
# pm
# Only Variable Labels on the outside (no axis labels)
pm <- ggpairs(tips[,1:3], axisLabels="none")
# pm

# Custom Examples
custom_car <- ggpairs(mtcars[,c("mpg","wt","cyl")], upper = "blank", title = "Custom Example")
# ggplot example taken from example(geom_text)
  plot <- ggplot2::ggplot(mtcars, ggplot2::aes(x=wt, y=mpg, label=rownames(mtcars)))
  plot <- plot +
    ggplot2::geom_text(ggplot2::aes(colour=factor(cyl)), size = 3) +
    ggplot2::scale_colour_discrete(l=40)
custom_car <- putPlot(custom_car, plot, 1, 2)
personal_plot <- ggally_text(
  "ggpairs allows you\nto put in your\nown plot.\nLike that one.\n <---"
)
custom_car <- putPlot(custom_car, personal_plot, 1, 3)
# custom_car

[Package GGally version 0.5.0 Index]