Which comparative layout to use? If using mc_layout_juxtaposition(), mcplot() will use juxtaposition layout to puts data observations and model predictions side by side in two seperated plots; if using mc_layout_superposition(), mcplot() overlays data observations and model predictions in one plot; if using mc_layout_encoding, mcplot() will show comparison by explicit-encoding; if using mc_layout_nested, mcplot() will show comparison side by side in one plot.

mc_layout_juxtaposition(...)

mc_layout_superposition()

mc_layout_nested(justification = 0.2)

mc_layout_encoding(transform)

Arguments

...

Other arguments passed on to cowplot::plot_grid(), when using juxtaposition.

justification

A number ro set the deviate from center when using nested juxtaposition. If justification is a positive number, model predictions will be on the right and data observations will be on the left; if justification is a negative number, the positions are reversed.

transform

What operation needs for explicit-encoding? If transform is:

  • "residual", then mcplot() will show the comparison between data observations and model predictions by a residual plot.

  • "qq", then mcplot() will show the comparison by a Q-Q plot.

  • "worm", then mcplot() will show the comparison by a detrended Q-Q plot (worm plot).

  • A function, then mcplot() will transform the data by that function. The input of the function is a data frame generated from the newdata data frame passed to mc_draw(), which includes a .row column (a factor grouping rows from the input newdata), .chain column (the chain each draw came from, or NA if the model does not provide chain information), .iteration column (the iteration the draw came from, or NA if the model does not provide iteration information), and a .draw column (a unique index corresponding to each draw from the distribution). The output of the function should includes a column named y_axis that specifies the data shown on y axis at least and an optional column named x_axis that specifies the data shown on x axis. If the output includes x_axis, mcplot() will ignore the conditional variable x defined in mc_condition_on(). See examples for more details.

Examples

library(ggplot2)
library(dplyr)
mcplot(mpg_model) +
  mc_layout_juxtaposition()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


mcplot(mpg_model) +
  mc_layout_superposition()
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


mcplot(mpg_model) +
  mc_layout_nested() +
  mc_condition_on(x = vars(vs))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


mcplot(mpg_model) +
  mc_layout_encoding("qq")
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.


# Defining a explicit encoding by a customized transform function to check
# stdandard residuals of model and data.

std_res_func = function(data) {
  data %>%
    mutate(y_axis = prediction - observation) %>%
    mutate(y_axis = y_axis / sd(y_axis))
}

mcplot(mpg_model) +
  mc_layout_encoding(std_res_func) +
  mc_condition_on(x = vars(disp)) +
  mc_gglayer(geom_hline(yintercept = 0))
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's fill values.