Controlling Plot Aesthetics

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Controlling plot aesthetics is very simple in dabestr. An integral part to the design of dabestr is to allow its users to freely adjust the various components of a DABEST estimation plot, allowing for the most ideal looking plot to be produced.

Getting started

At this point, we assume that you have already obtained the dabest_effectsize_obj. To add and adjust specific plot components, simply add it as a argument into the dabest_plot() function.

dabest_plot(
  dabest_effectsize_obj,
  float_contrast = TRUE,
  plot_component = "adjustment_value"
)

Adjusting Text

All text elements in the estimation plot can be adjusted. This includes the value, the size and even removal of the text elements completely.

Size

The following parameters are responsible for adjusting the size of the text elements.

library(dabestr)

data(non_proportional_data)
data(proportional_data)
data(deltadelta_data)
dabest_twogroup_obj.mean_diff <- load(non_proportional_data, x = Group, y = Measurement, idx = c("Control 1", "Test 1")) %>%
  mean_diff()

dabest_multigroup_obj.mean_diff <- load(non_proportional_data,
  x = Group, y = Measurement,
  idx = list(c("Control 1", "Test 1", "Test 2"), c("Control 2", "Test 3"))
) %>%
  mean_diff()

dabest_unpaired_props.mean_diff <- load(proportional_data,
  x = Group, y = Success,
  idx = list(c("Control 1", "Test 1")),
  proportional = TRUE
) %>%
  mean_diff()

dabest_paired_props.mean_diff <- load(proportional_data,
  x = Group, y = Success,
  idx = list(c("Control 1", "Test 1", "Test 2", "Test 3"), c("Control 2", "Test 4")),
  proportional = TRUE, paired = "sequential",
  id_col = ID
) %>%
  mean_diff()
dabest_plot(
  dabest_twogroup_obj.mean_diff,
  float_contrast = TRUE,
  swarm_x_text = 30,
  swarm_y_text = 1,
  contrast_x_text = 30,
  contrast_y_text = 5
)

Content

The following parameters are responsible for adjusting the content of the text elements.

dabest_plot(
  dabest_twogroup_obj.mean_diff,
  float_contrast = TRUE,
  swarm_label = "I love estimation statistics.",
  contrast_label = "I love it more than you do!"
)

Adjusting Visual Elements

Visual elements refer to the shapes, lines, symbols or other visual representations that convey data and relationship in a plot. Many of these elements can be adjusted in dabestr.

Markers

The following parameters are responsible for adjusting the properties of various markers in the plot.

A <- dabest_plot(dabest_twogroup_obj.mean_diff,
  float_contrast = TRUE,
  swarm_label = "", contrast_label = "",
  raw_marker_size = 1, raw_marker_alpha = 1
)
B <- dabest_plot(dabest_twogroup_obj.mean_diff,
  float_contrast = TRUE,
  swarm_label = "", contrast_label = "",
  raw_marker_size = 2, raw_marker_alpha = 0.5
)

cowplot::plot_grid(
  plotlist = list(A, B),
  nrow = 1,
  ncol = 2,
  labels = "AUTO"
)

Axes

The following parameters are responsible for adjusting the y-axis limits for the rawdata axes and contrast axes of the plot. By adjusting the range, it gives rise to the effect of zooming in or out of the plot.

If your effect size is qualitatively inverted (ie. a smaller value is a better outcome), you can invert the vector passed to contrast_ylim.

dabest_plot(dabest_multigroup_obj.mean_diff,
  float_contrast = FALSE,
  contrast_label = "More negative is better!",
  swarm_ylim = c(1, 5), contrast_ylim = c(0.7, -1.2)
)

Palettes

The following parameters are responsible for adjusting the plot palettes of the plot.

npg <- dabest_plot(dabest_unpaired_props.mean_diff,
  swarm_label = "", contrast_label = "",
  custom_palette = "npg"
)
nejm <- dabest_plot(dabest_unpaired_props.mean_diff,
  swarm_label = "", contrast_label = "",
  custom_palette = "nejm"
)
jama <- dabest_plot(dabest_unpaired_props.mean_diff,
  swarm_label = "", contrast_label = "",
  custom_palette = "jama"
)
locuszoom <- dabest_plot(dabest_unpaired_props.mean_diff,
  swarm_label = "", contrast_label = "",
  custom_palette = "locuszoom"
)

cowplot::plot_grid(
  plotlist = list(npg, nejm, jama, locuszoom),
  nrow = 2,
  ncol = 2
)

Misc

dabest_plot(dabest_paired_props.mean_diff, sankey = FALSE, raw_bar_width = 0.15)
dabest_plot(dabest_paired_props.mean_diff, flow = FALSE, raw_bar_width = 0.15)
right <- dabest_plot(dabest_twogroup_obj.mean_diff,
  float_contrast = FALSE,
  swarm_label = "", contrast_label = "",
  asymmetric_side = "right"
)
left <- dabest_plot(dabest_twogroup_obj.mean_diff,
  float_contrast = FALSE,
  swarm_label = "", contrast_label = "",
  asymmetric_side = "left"
)

cowplot::plot_grid(
  plotlist = list(right, left),
  nrow = 1,
  ncol = 2
)
dabest_plot(dabest_multigroup_obj.mean_diff,
  float_contrast = FALSE,
  show_baseline_ec = TRUE
)


Try the dabestr package in your browser

Any scripts or data that you put into this service are public.

dabestr documentation built on Oct. 13, 2023, 5:10 p.m.