Learn R Programming

speccurvieR (version 1.0.0)

plot_curve: Plots a specification curve.

Description

plot_curve() takes the data frame output of sca() and produces a ggplot of the independent variable's coefficient (as indicated in the call to sca()) across model specifications. By default a panel is added showing which control variables are present in each model. The combined plot is returned as a `patchwork` object, so it can be further customised with ggplot2 and patchwork operators (e.g. `& theme_sca(base_size = 14)`).

Usage

plot_curve(
  sca_data,
  title = "",
  show_index = TRUE,
  plot_vars = TRUE,
  ylab = "Coefficient",
  plot_se = "bar",
  median_line = FALSE,
  point_size = NULL
)

Value

If `plot_vars = TRUE` a `patchwork` object combining the curve and the variable panel; if `plot_vars = FALSE` a ggplot object. Both can be further customised with ggplot2 (and patchwork) operators.

Arguments

sca_data

A data frame returned by `sca()` containing model estimates from the specification curve analysis.

title

A string to use as the plot title. Defaults to an empty string, `""`.

show_index

A boolean indicating whether to label the model index on the the x-axis. Defaults to `TRUE`.

plot_vars

A boolean indicating whether to include a panel on the plot showing which variables are present in each model. Defaults to `TRUE`.

ylab

A string to be used as the y-axis label. Defaults to `"Coefficient"`.

plot_se

A string indicating whether to display standard errors as bars or plots. For bars `plot_se = "bar"`, for ribbons `plot_se = "ribbon"`. If any other value is supplied then no standard errors are included. Defaults to `"bar"`.

median_line

A boolean indicating whether to add a dotted line at the median coefficient across specifications. Defaults to `FALSE`.

point_size

A number giving the size of the plotted points. Defaults to `NULL`, in which case a size is chosen automatically from the number of specifications.

Examples

Run this code
plot_curve(sca_data = sca(y="Salnty", x="T_degC", c("ChlorA", "O2Sat"),
                         data=bottles, progress_bar=TRUE, parallel=FALSE),
                     title = "Salinity and Temperature Models",
                     show_index = TRUE, plot_vars = TRUE,
                     ylab = "Coefficient value", plot_se = "ribbon");
plot_curve(sca_data = sca(y="Salnty", x="T_degC",
                         c("ChlorA*O2Sat", "ChlorA", "O2Sat"),
                         data=bottles, progress_bar=FALSE, parallel=FALSE),
                     show_index = TRUE, plot_vars = TRUE,
                     plot_se = "ribbon");
# \donttest{
plot_curve(sca_data = sca(y="Salnty", x="T_degC",
                         c("ChlorA*NO3uM", "O2Sat", "ChlorA", "NO3uM"),
                         data=bottles,
                         progress_bar = TRUE, parallel = TRUE, workers=2),
          plot_se="");
# }

Run the code above in your browser using DataLab