ggheat2: ggheat2

Description Usage Arguments Details See Also Examples

View source: R/ggplots.R

Description

Function to plot a heat map using ggplot.

Usage

1
2
3
4
5
ggheat2(data, corr = cor(data, use = "pairwise.complete"), cluster = TRUE,
  nbreaks = NULL, palette = if (is.null(nbreaks)) c("blue", "white", "red")
  else 1, legend_name = expression(rho), pch, cex = c(2, 6),
  label = FALSE, label_alpha = FALSE, label_color = "black",
  label_digits = 2, midpoint = 0, clim = c(-1, 1), ...)

Arguments

data

a data frame or matrix (observations x variables) of numeric values

corr

a correlation matrix

cluster

logical or function; if TRUE, the variables will be clustered and reordered; if FALSE, no reordering will be done; otherwise, a custom clustering function may be given; see details

nbreaks

number of breaks to categorize the correlations (default is NULL, ie, a continuous scale)

palette

for a continuous scale, a vector of length three giving the low, mid, and high colors of the gradient (default is c('blue','white',''red), see scale_colour_gradient2); for a discrete scale, a character string of the palette name or an integer giving the index of the palette, see scale_colour_brewer

legend_name

the legend name; see discrete_scale

pch

(optional) plotting character; if missing, geom_tile is used instead of plotting characters

cex

size of pch; a vector of length one (all pch will be the same size) or two (size will be proportional to the correlation); default is c(2,6); seescale_size_identity

label

logical; if TRUE, adds correlation coefficients on top of each pch

label_alpha

logical, if TRUE, adds alpha transparency when label is TRUE (correlations closer to 0 will be less visible)

label_color

color of correlations (default is 'black')

label_digits

number of digits in correlation labels

midpoint

the midpoint value for continuous scaling of correlations (default is 0)

clim

vector of length two giving the limits of correlation coefficients (default is -1,1)

...

additional arguments passed to geom_text for the diagonal labels

Details

Default cluster method is stats::hclust(dist(x), method = 'average') which will return a list containing a named vector, "order", which is used to reorder the variables.

In order to pass a custom clustering function to cluster, the function must take a single input (a correlation matrix) and return either a vector or a list with a named vector, "order".

See Also

cor, ggheat, icorr, corrplot, https://github.com/briatte/ggcorr

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
library('ggplot2')
ggheat2(mtcars)

ggheat2(mtcars, label = TRUE, label_alpha = TRUE, cluster = FALSE,
        ## additional args passed to diagonal labels
        colour = 'red', angle = 45, size = 7)

ggheat2(mtcars, pch = 19, nbreaks = 6, cex = c(2,10),
        palette = 'PuOr',         ## colorblind palette
        size = 5, hjust = 0.75) + ## passed to diag text
    labs(title = 'Correlation Matrix')

## custom clustering function
ggheat2(data = NULL, corr = cor(mtcars, use = 'pairwise'),
        nbreaks = 5, palette = 'Blues',
        cluster = function(...) sample(ncol(mtcars)))

raredd/plotr documentation built on Nov. 13, 2018, 7:05 a.m.