# Yamlet Plot Aesthetics

#### Tim Bergsma

#### 2026-03-06

## Behavior

Plotting a decorated data.frame in ggplot() has special behavior for aesthetics defined using yamlet decorations. If there is only one dataset (typical), the aesthetics are coordinated with the (levels of the) corresponding variable.

If one or more additional layers provide non-default data, a single set of consensus decorations is accumulated, with each successive dataset overriding all previous decorations where conflicts exist; then, consensus decorations are enforced on all datasets.

## Example

In the example below, points are plotted using the observed data, then summary data is plotted as a separate layer, supplying its own data. the plot is rendered without decorations (left) and with decorations (right).

    library(magrittr)
    library(ggplot2)
    library(yamlet)
    library(dplyr)
    library(metaplot)

    set.seed(10)
    obs <- data.frame(
      time = 1:100,
      group = c('a','b'),
      concentration = rnorm(100)
    )

    # observed data
    obs %<>% decorate('
      time: [ Time, h ]
      concentration: [ Concentration, ng/mL ]
      group: [
        Group,
        [ a, b ],
        color: [ green, yellow ] ,
        linetype: [ dashed, dotdash ]
      ]
    ')

    # summary data
    sum <- obs %>% group_by(group) %>% summarize(mean = mean(concentration))
    sum %<>% undecorate %>% decorate('
      group: [
        Subset,
        [ a, b ],
        color: [ blue, magenta ],
        shape: [ 15, 19 ]
      ]
    ')

    q <- obs %>%
      undecorate %>%
      ggplot(aes(time, concentration)) +
      geom_point(aes(color = group, shape = group)) +
      geom_hline(
        data = undecorate(sum),
        aes(
          yintercept = mean,
          color = group,
          linetype = group
        )
      ) +
      theme(legend.position = "top") +
      labs(subtitle = 'without decorations') +
      symmetric()

    p <- obs %>%
      resolve %>%
      ggplot(aes(time, concentration)) +
      geom_point(aes(color = group, shape = group)) +
      geom_hline(
        data = resolve(sum),
        aes(
          yintercept = mean,
          color = group,
          linetype = group
        )
      ) +
      theme(legend.position = "top") +
      labs(subtitle = 'with decorations') +
      symmetric()

    multiplot(q, p) # %>% devsize(2,2)

    ## Warning: mismatched label attributes: ignoring 'Group' in favor of 'Subset'

- Notice that the label (on the right) for color and shape is ‘Subset’, not ‘Groups’, because the last layer wins.
- Likewise, colors are blue and magenta, not green and yellow, because the summary layer was supplied last.
- The summary layer respects the linetype defined earlier, having no such decoration in its own data.
- The observations layer respects the shapes defined with the summary layer, which in fact are not even used by the summary layer.

This example is a bit contrived for heuristic value. As a best practice, consider specifying all aesthetics in the default data only.

    sessionInfo()

    ## R version 4.5.2 (2025-10-31 ucrt)
    ## Platform: x86_64-w64-mingw32/x64
    ## Running under: Windows 11 x64 (build 26200)
    ##
    ## Matrix products: default
    ##   LAPACK version 3.12.1
    ##
    ## locale:
    ## [1] LC_COLLATE=C
    ## [2] LC_CTYPE=English_United States.utf8
    ## [3] LC_MONETARY=English_United States.utf8
    ## [4] LC_NUMERIC=C
    ## [5] LC_TIME=English_United States.utf8
    ##
    ## time zone: America/New_York
    ## tzcode source: internal
    ##
    ## attached base packages:
    ## [1] stats     graphics  grDevices utils     datasets  methods   base
    ##
    ## other attached packages:
    ## [1] metaplot_0.8.4 dplyr_1.1.4    yamlet_1.3.3   ggplot2_4.0.1  magrittr_2.0.4
    ##
    ## loaded via a namespace (and not attached):
    ##  [1] sass_0.4.10        generics_0.1.4     tidyr_1.3.1        xml2_1.5.1
    ##  [5] lattice_0.22-7     stringi_1.8.7      digest_0.6.39      evaluate_1.0.5
    ##  [9] grid_4.5.2         RColorBrewer_1.1-3 fastmap_1.2.0      jsonlite_2.0.0
    ## [13] latexpdf_0.1.8     gridExtra_2.3      purrr_1.2.0        viridisLite_0.4.2
    ## [17] scales_1.4.0       textshaping_1.0.4  jquerylib_0.1.4    csv_0.6.2
    ## [21] cli_3.6.5          rlang_1.1.6        units_1.0-0        withr_3.0.2
    ## [25] cachem_1.1.0       yaml_2.3.12        tools_4.5.2        kableExtra_1.4.0
    ## [29] vctrs_0.6.5        R6_2.6.1           png_0.1-8          spork_0.3.5
    ## [33] lifecycle_1.0.4    stringr_1.6.0      pkgconfig_2.0.3    pillar_1.11.1
    ## [37] bslib_0.9.0        gtable_0.3.6       data.table_1.17.8  glue_1.8.0
    ## [41] Rcpp_1.1.0         systemfonts_1.3.1  xfun_0.55          tibble_3.3.0
    ## [45] tidyselect_1.2.1   rstudioapi_0.17.1  knitr_1.50         farver_2.1.2
    ## [49] xtable_1.8-4       htmltools_0.5.9    labeling_0.4.3     rmarkdown_2.30
    ## [53] svglite_2.2.2      compiler_4.5.2     S7_0.2.1           encode_0.3.6