"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 andinherit.aes = TRUE(the default), it is combined with the default mapping at the top level of the plot. You must supplymappingif 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()'sparamsargument. These arguments broadly fall into one of 4 categories below. Notably, further arguments to thepositionargument, 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"orlinewidth = 3. The geom's documentation has an Aesthetics section that lists the available options. The 'required' aesthetics cannot be passed on to theparams. 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 thegeompart of the layer. An example of this isstat_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 thestatpart of the layer. An example of this isgeom_area(stat = "density", adjust = 0.5). The stat's documentation lists which parameters it can accept.The
key_glyphargument oflayer()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.
Aesthetics
add_marker() understands the following aesthetics (required aesthetics are in bold)
when using color/colour similar to geom_point().
xycolor/colourname*alphagroupshapesizestroke
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.
xylabel_vals
label_names*alphaanglefamilyfontfacegrouphjustlineheightsizevjust
Notes:
add_marker()does not support mapping usingfill.If using a fixed/non-mapping
colorspecifier, a mappingnameis required for aesthetic mapping to render the legend value label correctly.If using a fixed/non-mapping
colorspecifier, afixed_marker_namemust be set for the first marker in a given new scale.If using labels, both
label_valsandlabel_namesare required for proper legend population. At minimum,label_valsis needed for data display. These are unique parameter options foraes()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
