Skip to content

geom_strip breaks with aes(linetype) #676

@joelnitta

Description

@joelnitta

geom_strip() results in an error when used in combination with aes(linetype = ...) in ggtree().

Reproducible example:

library(ggtree)
#> Warning: package 'ggtree' was built under R version 4.5.1
#> ggtree v3.16.3 Learn more at https://yulab-smu.top/contribution-tree-data/
#> 
#> Please cite:
#> 
#> Guangchuang Yu. Using ggtree to visualize data on tree-like structures.
#> Current Protocols in Bioinformatics. 2020, 69:e96. doi:10.1002/cpbi.96

# Create a simple tree
tree <- ape::read.tree(text = "((a:1,b:1):1,c:2);")

# Generate data for mapping
tip_data <- tidytree::as_tibble(ggtree::fortify(tree))
tip_data$group <- c(TRUE, TRUE, FALSE, TRUE, TRUE)

# Linetype only: works
ggtree(tree, aes(linetype = group)) %<+%
  tip_data +
  geom_tiplab()

# Strip labels only: works
ggtree(tree) %<+%
  tip_data +
  geom_strip(
    taxa1 = "a",
    taxa2 = "b",
    label = "Clade AB"
  )

# Linetype plus strip label: doesn't work
ggtree(tree, aes(linetype = group)) %<+%
  tip_data +
  geom_strip(
    taxa1 = "a",
    taxa2 = "b",
    label = "Clade AB"
  )
#> Error in `geom_segment()`:
#> ! Problem while computing aesthetics.
#> ℹ Error occurred in the 3rd layer.
#> Caused by error:
#> ! object 'group' not found

Created on 2025-10-29 with reprex v2.1.1

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.5.0 (2025-04-11)
#>  os       macOS Sonoma 14.6.1
#>  system   aarch64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       Asia/Tokyo
#>  date     2025-10-29
#>  pandoc   3.1.2 @ /usr/local/bin/ (via rmarkdown)
#>  quarto   1.6.39 @ /Applications/quarto/bin/quarto
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package      * version date (UTC) lib source
#>  ape            5.8-1   2024-12-16 [1] CRAN (R 4.5.0)
#>  aplot          0.2.8   2025-07-02 [1] CRAN (R 4.5.0)
#>  cli            3.6.5   2025-04-23 [1] CRAN (R 4.5.0)
#>  curl           7.0.0   2025-08-19 [1] CRAN (R 4.5.0)
#>  digest         0.6.37  2024-08-19 [1] CRAN (R 4.5.0)
#>  dplyr          1.1.4   2023-11-17 [1] CRAN (R 4.5.0)
#>  evaluate       1.0.3   2025-01-10 [1] CRAN (R 4.5.0)
#>  farver         2.1.2   2024-05-13 [1] CRAN (R 4.5.0)
#>  fastmap        1.2.0   2024-05-15 [1] CRAN (R 4.5.0)
#>  fs             1.6.6   2025-04-12 [1] CRAN (R 4.5.0)
#>  generics       0.1.4   2025-05-09 [1] CRAN (R 4.5.0)
#>  ggfun          0.2.0   2025-07-15 [1] CRAN (R 4.5.0)
#>  ggplot2        3.5.2   2025-04-09 [1] CRAN (R 4.5.0)
#>  ggplotify      0.1.2   2023-08-09 [1] CRAN (R 4.5.0)
#>  ggtree       * 3.16.3  2025-07-14 [1] bioc (@3.16.3)
#>  glue           1.8.0   2024-09-30 [1] CRAN (R 4.5.0)
#>  gridGraphics   0.5-1   2020-12-13 [1] CRAN (R 4.5.0)
#>  gtable         0.3.6   2024-10-25 [1] CRAN (R 4.5.0)
#>  htmltools      0.5.8.1 2024-04-04 [1] CRAN (R 4.5.0)
#>  jsonlite       2.0.0   2025-03-27 [1] CRAN (R 4.5.0)
#>  knitr          1.50    2025-03-16 [1] CRAN (R 4.5.0)
#>  labeling       0.4.3   2023-08-29 [1] CRAN (R 4.5.0)
#>  lattice        0.22-6  2024-03-20 [1] CRAN (R 4.5.0)
#>  lazyeval       0.2.2   2019-03-15 [1] CRAN (R 4.5.0)
#>  lifecycle      1.0.4   2023-11-07 [1] CRAN (R 4.5.0)
#>  magrittr       2.0.3   2022-03-30 [1] CRAN (R 4.5.0)
#>  nlme           3.1-168 2025-03-31 [1] CRAN (R 4.5.0)
#>  patchwork      1.3.1   2025-06-21 [1] CRAN (R 4.5.0)
#>  pillar         1.11.0  2025-07-04 [1] CRAN (R 4.5.0)
#>  pkgconfig      2.0.3   2019-09-22 [1] CRAN (R 4.5.0)
#>  purrr          1.1.0   2025-07-10 [1] CRAN (R 4.5.0)
#>  R6             2.6.1   2025-02-15 [1] CRAN (R 4.5.0)
#>  RColorBrewer   1.1-3   2022-04-03 [1] CRAN (R 4.5.0)
#>  Rcpp           1.1.0   2025-07-02 [1] CRAN (R 4.5.0)
#>  reprex         2.1.1   2024-07-06 [1] CRAN (R 4.5.0)
#>  rlang          1.1.6   2025-04-11 [1] CRAN (R 4.5.0)
#>  rmarkdown      2.29    2024-11-04 [1] CRAN (R 4.5.0)
#>  scales         1.4.0   2025-04-24 [1] CRAN (R 4.5.0)
#>  sessioninfo    1.2.3   2025-02-05 [1] CRAN (R 4.5.0)
#>  tibble         3.3.0   2025-06-08 [1] CRAN (R 4.5.0)
#>  tidyr          1.3.1   2024-01-24 [1] CRAN (R 4.5.0)
#>  tidyselect     1.2.1   2024-03-11 [1] CRAN (R 4.5.0)
#>  tidytree       0.4.6   2023-12-12 [1] CRAN (R 4.5.0)
#>  treeio         1.32.0  2025-04-15 [1] Bioconduc~
#>  vctrs          0.6.5   2023-12-01 [1] CRAN (R 4.5.0)
#>  withr          3.0.2   2024-10-28 [1] CRAN (R 4.5.0)
#>  xfun           0.52    2025-04-02 [1] CRAN (R 4.5.0)
#>  xml2           1.3.8   2025-03-14 [1] CRAN (R 4.5.0)
#>  yaml           2.3.10  2024-07-26 [1] CRAN (R 4.5.0)
#>  yulab.utils    0.2.0   2025-01-29 [1] CRAN (R 4.5.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
#>  * ── Packages attached to the search path.
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions