Skip to contents

Plot of residual structures classified by a Weighted Scale.

Usage

fn_fig_w(df, opacity, tint, my_labeller, order, lab_x, lab_y)

Arguments

df

A data frame contains the following variables: independent (x) and dependent (y) variables, the fitted variable (fitt), a weighted variable (wi), and additional details including the weights (wi), fitted values (fitt), residuals (ei), and the scale.

opacity

A numeric value for the alpha aesthetic used to control the transparency of elements in a plot.

tint

A vector that specifies the palette colors used to color the points.

my_labeller

Transforms objects to labeller functions. Used internally by labeller().

order

A vector determines the sequence of the plots.

lab_x

A string contains the x-axis label.

lab_y

A string contains the y-axis label.

Value

A customized multi-panel plot that uses a color scale for the residual points.

Details

The residual structure was analyzed by graphing residuals against weighted values. A custom multi-panel plot illustrates the structure of each fitted relationship, categorized by a color-weighted scale of values.

To standardize the x-axis units across different fitted models, a standardized residual distance, such as studentized residuals, can be used due to the varying dimensions of the variables.

Since the parameters contain subscripts, the labels were customized using the `ggplot2::as_labeller()` function and are stored in `my_labeller`. The axis labels also contain subscripts and are defined in x-axis and y-axis.

See also

ggplot2::as_labeller()

ggplot2::facet_wrap

forcats::fct_relevel

Examples

 if (FALSE) { # \dontrun{
 ## Data frame
 seed <- set.seed(123)
 id <- rep("LT_LS"," LT_LB", "LS_LB", each=30)
 ei <- c(runif(80, -2.5,2.5),runif(10, -4,4))
 scale <- ifelse(abs(ei) < 2, "u", ifelse(abs(ei) >= 2 & abs(ei) <2.5, "W", "o"))
 wi <- round(ifelse(scale=="u", runif(1, 0.9, 1), ifelse(scale=="W",
                    runif(1, 0.3, 0.89), runif(1, 0, 0.29))),2)
 df <-data.frame(id=id, ei=ei, wi=wi, scale=scale)

 opacity <- 1/5  # alpha
 tint <- c("#000000","#009E73", "#56B4E9")
 my_labeller <- as_labeller(c(LT_LS=  "L[T]-L[S]",
                              LT_LB=  "L[T]-L[B]",
                              LS_LB=  "L[S]-L[B]",
                              default = label_parsed))
 order <- c("LT_LS", "LT_LB",  "LS_LB")
 lab_x <- expression(italic(e[i]))
 lab_y <- expression(italic(w[i]))


 p <- fn_fig_w(df, opacity, tint, my_labeller, order, lab_x, lab_y)
} # }