pcp_scale: Data wrangling for GPCPs: Step 2 scale values

View source: R/pcp_scale.r

pcp_scaleR Documentation

Data wrangling for GPCPs: Step 2 scale values

Description

The function pcp_scale provides access to a set of transformations to use in parallel coordinate plots. All transformations other than raw tend to produce y values in the interval from 0 and 1.

Usage

pcp_scale(data, method = "uniminmax", .by_group = TRUE)

Arguments

data

data frame as returned by select_pcp

method

string specifying the method that should be used for scaling the values in a parallel coordinate plot (see Details).

.by_group

logical value. If TRUE, scaling will respect any previous grouping variables. Applies to grouped data frames only.

Details

The data pipeline feeding any of the geom layers in the ggpcp package is implemented in a three-step modularized form rather than as the stat functions more typical for ggplot2 extensions. The three steps of data pre-processing are:

command data processing step
pcp_select variable selection (and horizontal ordering)
pcp_scale (vertical) scaling of values
pcp_arrange dealing with tie-breaks on categorical axes

Note that these data processing steps are executed before the call to ggplot2 and the identity function is used by default in all of the ggpcp specific layers. Besides the speed-up by only executing the processing steps once for all layers, the separation has the additional benefit, that it provides the users with the possibility to make specific choices at each step in the process. Additionally, separation allows for a cleaner user interface: parameters affecting the data preparation process can be moved to the relevant (set of) function(s) only, thereby reducing the number of arguments without any loss of functionality.

method is a character string that denotes how to scale the variables in the parallel coordinate plot. Options are named in the same way as the options in GGally::ggparcoord():

  • raw: raw data used, no scaling will be done.

  • std: univariately, subtract mean and divide by standard deviation. To get values into a unit interval we use a linear transformation of f(y) = y/4+0.5.

  • robust: univariately, subtract median and divide by median absolute deviation. To get values into an expected interval of unit interval we use a linear transformation of f(y) = y/4+0.5.

  • uniminmax: univariately, scale so the minimum of the variable is zero, and the maximum is one.

  • globalminmax: global scaling; the global maximum is mapped to 1, global minimum across the variables is mapped to 0.

Value

data frame of the same size as the input data; values of pcp_y and pcp_yend are scaled according to the specified method.

See Also

pcp_select(), pcp_arrange()

Examples

data(Carcinoma)
dim(Carcinoma)
# select all variables
pcp_data <- Carcinoma |> pcp_select(1:9)
summary(pcp_data)
pcp_data |> pcp_scale() |> summary()
# scaling gets values of pcp_y and pcp_yend between 0 and 1

ggpcp documentation built on Nov. 28, 2022, 5:05 p.m.