Skip to contents

"Markers" are used to specify events of interest along response trajectories across individual lanes. add_marker() wraps geom_point() or geom_label() depending on the users designation of color/colour and label_vals/label_names arguments.

See Aesthetics for more information.

Usage

add_marker(mapping = aes(), data = NULL, fixed_marker_name = NULL, ...)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

a dataframe prepared for use with ggswim()

fixed_marker_name

A character string for the name of a fixed marker scale

...

Other arguments passed on to layer()'s params argument. These arguments broadly fall into one of 4 categories below. Notably, further arguments to the position argument, or aesthetics that are required can not be passed through .... Unknown arguments that are not part of the 4 categories below are ignored.

  • Static aesthetics that are not mapped to a scale, but are at a fixed value and apply to the layer as a whole. For example, colour = "red" or linewidth = 3. The geom's documentation has an Aesthetics section that lists the available options. The 'required' aesthetics cannot be passed on to the params. Please note that while passing unmapped aesthetics as vectors is technically possible, the order and required length is not guaranteed to be parallel to the input data.

  • When constructing a layer using a stat_*() function, the ... argument can be used to pass on parameters to the geom part of the layer. An example of this is stat_density(geom = "area", outline.type = "both"). The geom's documentation lists which parameters it can accept.

  • Inversely, when constructing a layer using a geom_*() function, the ... argument can be used to pass on parameters to the stat part of the layer. An example of this is geom_area(stat = "density", adjust = 0.5). The stat's documentation lists which parameters it can accept.

  • The key_glyph argument of layer() may also be passed on through .... This can be one of the functions described as key glyphs, to change the display of the layer in the legend.

Value

A ggswim object

Aesthetics

add_marker() understands the following aesthetics (required aesthetics are in bold) when using color/colour similar to geom_point().

  • x

  • y

  • color/colour

  • name *

  • alpha

  • group

  • shape

  • size

  • stroke

add_marker() understands the following aesthetics (required aesthetics are in bold) when using label_vals/label_names similar to geom_label(). See "Notes" below for additional considerations and requirements.

  • x

  • y

  • label_vals

  • label_names *

  • alpha

  • angle

  • family

  • fontface

  • group

  • hjust

  • lineheight

  • size

  • vjust

Notes:

  • add_marker() does not support mapping using fill.

  • If using a fixed/non-mapping color specifier, a mapping name is required for aesthetic mapping to render the legend value label correctly.

  • If using a fixed/non-mapping color specifier, a fixed_marker_name must be set for the first marker in a given new scale.

  • If using labels, both label_vals and label_names are required for proper legend population. At minimum, label_vals is needed for data display. These are unique parameter options for aes() to ggswim.

Examples


# markers with points and aesthetic mapping params
add_marker(
  data = infusion_events |> dplyr::mutate(infusion = "Infusion"),
  mapping = aes(
    x = time_from_initial_infusion,
    y = pt_id,
    color = infusion
  ),
  size = 5
)
#> mapping: x = ~time_from_initial_infusion, y = ~pt_id, colour = ~infusion 
#> geom_point: na.rm = TRUE
#> stat_identity: na.rm = TRUE
#> position_identity 

# markers with points and fixed params

initial_infusions <- infusion_events |>
  dplyr::filter(time_from_initial_infusion == 0)

add_marker(
  data = initial_infusions,
  mapping = aes(
    x = time_from_initial_infusion,
    y = pt_id,
    name = "Initial Infusion"
  ),
  color = "red",
  size = 5
)
#> Warning: Duplicated aesthetics after name standardisation: colour
#> mapping: x = ~time_from_initial_infusion, y = ~pt_id, colour = ~`Initial Infusion` 
#> geom_point: na.rm = TRUE
#> stat_identity: na.rm = TRUE
#> position_identity 

# markers with labels
add_marker(
  data = end_study_events,
  mapping = aes(
    y = pt_id, x = time_from_initial_infusion,
    label_names = end_study_name,
    label_vals = end_study_label
  ),
  label.size = NA, fill = NA, size = 5
)
#> mapping: x = ~time_from_initial_infusion, y = ~pt_id, colour = ~end_study_name, label = ~end_study_label 
#> geom_label: parse = FALSE, label.padding = 0.25, label.r = 0.15, label.size = NA, size.unit = mm, na.rm = FALSE
#> stat_identity: na.rm = FALSE
#> position_identity