add_funtext: User-specified text labels in off-diagonal ggcorrm facets

Description Usage Arguments Details Value See Also Examples

Description

lotri_funtext() and utri_funtext() are used to display user-specified text labels in the off-diagonal facets of ggcorrm plots.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
lotri_funtext(
  fun,
  mapping = NULL,
  nrow = NULL,
  ncol = NULL,
  squeeze = 0.5,
  byrow = TRUE,
  show.legend = FALSE,
  ...
)

utri_funtext(
  fun,
  mapping = NULL,
  nrow = NULL,
  ncol = NULL,
  squeeze = 0.5,
  byrow = TRUE,
  show.legend = FALSE,
  ...
)

Arguments

fun

One of the following: * a) a function of x and y. * b) an rlang lambda style one-sided formula describing a function of two parameters labeled.x and .y * c) an rlang quosure created with quo() that is evaluated in the context of the data analogous to the mutates argument in tidy_corrm().

The functions in a) and b) are evaluated using the x and ycoordinates of the plot as first and second argument, respectively. The quosure in c) is evaluated in the context of the raw data and may contain x and y.

One outcome of the computation per group is stored in a new column called fun_out that can be accessed in the aesthetics using..fun_out...

mapping

Set of aesthetic mappings created by aes(). x and y are set automatically and must not bechanged, but all other aesthetics may be manipulated. By default, the fill aesthetic is mapped to ..fun_out.. internally, but this is overridden when explicitly specified. Defaults to NULL (use standard settings).

nrow

integer - the number of rows for the correlation labels if grouping aesthetics are present (defaults to NULL - automatic setting of nrow).

ncol

integer - the number of columns for the correlation labels if grouping aesthetics are present (defaults to NULL - automatic setting of ncol).

squeeze

numeric between 0 an 1. Proportion of the facet width/height the facet labels are restricted to when multiple labels are present (defaults to 0.7 - labels extend over 70% of the extent of the plot).

byrow

logical. Should the correlation labels in plots with multiple groups be filled by rows (byrow = TRUE) or by columns (byrow = FALSE)? Note that the actual number of rows or columns that are filled with values can be below the specified value of nrow or ncol when less rows/columns than specified are needed to reach the total number of groups. Defaults to TRUE.

show.legend

logical. Should this layer be included in the legends? FALSE (the default) never includes, TRUE always includes, and NA includes only if aesthetics are mapped. It can also be a named logical vector to finely select the aesthetics to display.

...

Additional arguments to stat_funtext.

Details

lotri_funtext() and utri_funtext() can be used to display user- defined text labels in the lower or upper triangular facets of ggcorrm plots, respectively. The functions can be evaluated separately for different groups by using grouping aesthetics such as aes(color = group).

If fun is a function or rlang lambda-style one-sided formula, it is called on the data in each group using the x coordinate as first and the y coordinate as second argument. If fun is a quosure, it is evaluated in the context of the data in the respective group.

lotri_funtext() and utri_funtext() are wrappers around stat_funtext() that additionally take care of the right specification of aesthetics. The positioning of the labels in stat_funtext() follows the same rules as in stat_corrtext().

Value

A ggplot2 layer with text labels for user_specified functions.

See Also

stat_funtext

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## Not run: 
if(interactive()){

# function to compute linear model slopes
lmslope <- function(y, x)  round(coef(lm(y ~ x))[2], 2)

# add slopes using a function
ggcorrm(drosera, rescale = "as_is") +
  lotri(geom_point(alpha = 0.4)) +
  utri_funtext(fun = lmslope) +
  dia_density(fill = "steelblue", lower = .4) +
  dia_names(y_pos = .1)

# compute Pearson correlations as a lambda expression (top)
# and as a quosure(bottom)
ggcorrm(drosera, rescale = "as_is") +
  utri_funtext(fun = ~ round(cor(.x, .y), 3)) +
  lotri_funtext(fun = quo(round(cor(x, y), 3))) +
  dia_names(y_pos = .5)

}

## End(Not run)

r-link/corrmorant documentation built on Jan. 10, 2021, 7:26 p.m.