Learn R Programming

see (version 0.4.1)

data_plot: Prepare objects for plotting or plot objects

Description

data_plot() attempts to extract and tranform an object to be further plotted, while plot() tries to visualize results of functions from different packages of the easystats-project.

Usage

data_plot(x, data = NULL, ...)

# S3 method for see_bayesfactor_models plot( x, n_pies = c("one", "many"), value = c("none", "BF", "probability"), sort = FALSE, log = FALSE, prior_odds = NULL, ... )

# S3 method for see_bayesfactor_parameters plot( x, point_size = 2, rope_color = "#0171D3", rope_alpha = 0.2, show_intercept = FALSE, ... )

# S3 method for see_check_distribution plot(x, point_size = 2, panel = TRUE, ...)

# S3 method for see_check_normality plot(x, type = c("density", "qq", "pp"), data = NULL, ...)

# S3 method for see_check_outliers plot(x, text_size = 3.5, ...)

# S3 method for see_cluster_analysis plot(x, data = NULL, n_columns = NULL, size = 0.6, ...)

# S3 method for see_compare_performance plot(x, size = 1, ...)

# S3 method for see_easycorrelation plot(x, size = 22, text_color = "white", node_color = "#647687", ...)

# S3 method for see_equivalence_test plot( x, rope_color = "#0171D3", rope_alpha = 0.2, show_intercept = FALSE, n_columns = 1, ... )

# S3 method for see_estimate_density plot( x, stack = TRUE, show_intercept = FALSE, n_columns = 1, priors = FALSE, priors_alpha = 0.4, size = 0.9, ... )

# S3 method for see_hdi plot( x, data = NULL, show_intercept = FALSE, show_zero = TRUE, show_title = TRUE, n_columns = 1, ... )

# S3 method for see_n_factors plot(x, data = NULL, type = c("bar", "line", "area"), size = 1, ...)

# S3 method for see_p_direction plot( x, data = NULL, show_intercept = FALSE, priors = FALSE, priors_alpha = 0.4, n_columns = 1, ... )

# S3 method for see_p_significance plot( x, data = NULL, show_intercept = FALSE, priors = FALSE, priors_alpha = 0.4, n_columns = 1, ... )

# S3 method for see_parameters_model plot( x, show_intercept = FALSE, point_size = 0.8, sort = NULL, n_columns = NULL, ... )

# S3 method for see_parameters_pca plot( x, type = c("bar", "line"), text_size = 3.5, text_color = "black", size = 1, ... )

# S3 method for see_parameters_sem plot( x, data = NULL, type = c("regression", "correlation", "loading"), threshold_coefficient = NULL, threshold_p = NULL, ci = TRUE, size = 22, ... )

# S3 method for see_parameters_simulate plot( x, data = NULL, stack = TRUE, show_intercept = FALSE, n_columns = NULL, ... )

# S3 method for see_point_estimate plot( x, data = NULL, point_size = 2, text_size = 3.5, panel = TRUE, show_labels = TRUE, show_intercept = FALSE, priors = FALSE, priors_alpha = 0.4, ... )

# S3 method for see_rope plot( x, data = NULL, rope_alpha = 0.5, rope_color = "cadetblue", show_intercept = FALSE, n_columns = 1, ... )

# S3 method for see_si plot( x, si_color = "#0171D3", si_alpha = 0.2, show_intercept = FALSE, support_only = FALSE, ... )

Arguments

x

An object.

data

The original data used to create this object. Can be a statistical model or such.

...

Arguments passed to or from other methods.

n_pies

Number of pies.

value

What value to display.

sort
Plotting model parameters

If NULL, coefficients are plotted in the order as they appear in the summary. Use sort = "ascending" (or sort = TRUE)) resp. sort = "descending" to sort coefficients in ascending or descending order.

Plotting Bayes factors

Sort pie-slices by posterior probability (descending)?

log

Show log-transformed Bayes factors.

prior_odds

optional vector of prior odds for the models. See BayesFactor::priorOdds. As the size of the pizza slices corresponds to posterior probability (which is a function of prior probability and the BF), custom prior_odds will change the slices' size.

point_size

Size of point-geoms.

rope_color, si_color

Color of ROPE/SI ribbon.

rope_alpha, si_alpha

Transparency level of ROPE/SI ribbon.

show_intercept

Logical, if TRUE, the intercept-parameter is included in the plot. By default, it is hidden because in many cases the intercept-parameter has a posterior distribution on a very different location, so density curves of posterior distributions for other parameters are hardly visible.

panel

Logical, if TRUE, plots are arranged as panels; else, single plots are returned.

type

Character vector, indicating the type of plot (for check_normality, parameters::model_parameters.lavaan or n_factors).

text_size

Size of text labels.

n_columns

For models with multiple components (like fixed and random, count and zero-inflated), defines the number of columns for the panel-layout. If NULL, a single, integrated plot is shown.

size

Size of geoms. Depends on the context of the plot() function, so this argument may change size of points, lines or bars.

text_color

Color of text labels.

node_color

Color of node- or circle-geoms.

stack

Logical, if TRUE, densities are plotted as stacked lines. Else, densities are plotted for each parameter among each other.

priors

Logical, if TRUE, prior distributions are simulated (using simulate_prior) and added to the plot.

priors_alpha

Alpha value of the prior distributions.

show_zero

Logical, if TRUE, will add a vertical (dotted) line at 0.

show_title

Logical, if TRUE, will show the title of the plot.

threshold_coefficient

Numeric, threshold at which value coefficients will be displayed.

threshold_p

Numeric, threshold at which value p-values will be displayed.

ci

Logical, whether confidence intervals should be added to the plot.

show_labels

Logical, if TRUE, the text labels for the point estimates (i.e. "Mean", "Median" and/or "MAP") are shown. You may set show_labels = FALSE in case of overlapping labels, and add your own legend or footnote to the plot.

support_only

Plot only the support data, or show the "raw" prior and posterior distributions? Only applies when plotting si.

Details

data_plot() is in most situation not needed when the purpose is plotting, since most plot()-functions in see internally call data_plot() to prepare the data for plotting.

Many plot()-functions have a data-argument that is needed when the data or model for plotting can't be retrieved via data_plot(). In such cases, plot() gives an error and asks for providing data or models.

Most plot()-functions work out-of-the-box, i.e. you don't need to do much more than calling plot(<object>) (see 'Examples'). Some plot-functions allow to specify arguments to modify the transparancy or color of geoms, these are shown in the 'Usage' section.

Plot-functions are available for objects from following functions (note that functions from packages might be listed here that are currently still in development and probably not yet available):

  • bayestestR::bayesfactor_models()

  • bayestestR::bayesfactor_parameters()

  • bayestestR::ci()

  • bayestestR::equivalence_test()

  • bayestestR::estimate_density()

  • bayestestR::eti()

  • bayestestR::hdi()

  • bayestestR::map_estimate()

  • bayestestR::p_direction()

  • bayestestR::p_significance()

  • bayestestR::point_estimate()

  • bayestestR::rope()

  • bayestestR::si()

  • correlation::correlation()

  • modelbased::estimate_contrasts()

  • parameters::cluster_analysis()

  • parameters::model_parameters()

  • parameters::n_factors()

  • parameters::simulate_parameters()

  • parameters::principal_components()

  • performance::binned_residuals()

  • performance::check_collinearity()

  • performance::check_distribution()

  • performance::check_heteroscedasticity()

  • performance::check_homogeneity()

  • performance::check_model()

  • performance::check_normality()

  • performance::check_outliers()

  • performance::compare_performance()

  • performance::performance_roc()

See Also

Package-Vignettes

Examples

Run this code
# NOT RUN {
library(bayestestR)
if (require("rstanarm")) {
  model <- stan_glm(
    Sepal.Length ~ Petal.Width * Species,
    data = iris,
    chains = 2, iter = 200
  )

  x <- rope(model)
  plot(x)

  x <- hdi(model)
  plot(x) + theme_modern()

  data <- rnorm(1000, 1)
  x <- p_direction(data)
  plot(x)

  x <- p_direction(model)
  plot(x)

  model <- stan_glm(
    mpg ~ wt + gear + cyl + disp,
    chains = 2,
    iter = 200,
    data = mtcars
  )
  x <- equivalence_test(model)
  plot(x)
}
# }
# NOT RUN {
library(bayestestR)
library(see)

lm0 <- lm(qsec ~ 1, data = mtcars)
lm1 <- lm(qsec ~ drat, data = mtcars)
lm2 <- lm(qsec ~ wt, data = mtcars)
lm3 <- lm(qsec ~ drat + wt, data = mtcars)

result <- bayesfactor_models(lm1, lm2, lm3, denominator = lm0)

plot(result, n_pies = "one", value = "probability") + theme_modern() +
  scale_fill_pizza(reverse = TRUE)
# }

Run the code above in your browser using DataLab