Need advice: labels for x-axis in comp_barplot() (calculate dominant taxon walkthrough) #138
Unanswered
RachBioHaz
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Glad you're finding the package useful :) Something like this code below is maybe helpful? the trick being pasting the dominant taxon variable and the subject or sample variable together into a new variable and then specifying that as the bar label library(ggplot2)
library(microViz)
#> microViz version 0.12.1 - Copyright (C) 2021-2024 David Barnett
#> ! Website: https://david-barnett.github.io/microViz
#> ✔ Useful? For citation details, run: `citation("microViz")`
#> ✖ Silence? `suppressPackageStartupMessages(library(microViz))`
ps <- microViz::ibd %>%
tax_filter(min_prevalence = 3) %>%
tax_fix()
# "portrait" orientation, to fit long labels
ps %>%
ps_filter(DiseaseState == "CD", age < 14) %>%
ps_calc_dominant(rank = "Genus", var = "dominant_genus") %>%
ps_mutate(sample_and_genus = paste(sample, dominant_genus, sep = ": ")) %>%
comp_barplot(tax_level = "Genus", label = "sample_and_genus", n_taxa = 12) +
coord_flip()
#> Registered S3 method overwritten by 'seriation':
#> method from
#> reorder.hclust vegan # or "landscape" with linebreaks, if you have enough space for the labels
ps %>%
ps_filter(DiseaseState == "CD", age < 14, gender == "female") %>%
ps_calc_dominant(rank = "Genus", var = "dominant_genus") %>%
ps_mutate(sample_and_genus = paste(sample, dominant_genus, sep = "\n")) %>%
comp_barplot(tax_level = "Genus", label = "sample_and_genus", n_taxa = 12) Created on 2024-01-27 with reprex v2.1.0 Session infosessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.3.2 (2023-10-31)
#> os macOS Sonoma 14.2.1
#> system x86_64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Amsterdam
#> date 2024-01-27
#> pandoc 3.1.1 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> ade4 1.7-22 2023-02-06 [1] CRAN (R 4.3.0)
#> ape 5.7-1 2023-03-13 [1] CRAN (R 4.3.0)
#> Biobase 2.62.0 2023-10-24 [1] Bioconductor
#> BiocGenerics 0.48.1 2023-11-01 [1] Bioconductor
#> biomformat 1.30.0 2023-10-24 [1] Bioconductor
#> Biostrings 2.70.1 2023-10-25 [1] Bioconductor
#> bitops 1.0-7 2021-04-24 [1] CRAN (R 4.3.0)
#> ca 0.71.1 2020-01-24 [1] CRAN (R 4.3.0)
#> cli 3.6.2 2023-12-11 [1] CRAN (R 4.3.0)
#> cluster 2.1.6 2023-12-01 [1] CRAN (R 4.3.0)
#> codetools 0.2-19 2023-02-01 [1] CRAN (R 4.3.2)
#> colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0)
#> crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0)
#> curl 5.2.0 2023-12-08 [1] CRAN (R 4.3.0)
#> data.table 1.14.10 2023-12-08 [1] CRAN (R 4.3.0)
#> digest 0.6.34 2024-01-11 [1] CRAN (R 4.3.0)
#> dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.3.0)
#> evaluate 0.23 2023-11-01 [1] CRAN (R 4.3.0)
#> fansi 1.0.6 2023-12-08 [1] CRAN (R 4.3.0)
#> farver 2.1.1 2022-07-06 [1] CRAN (R 4.3.0)
#> fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0)
#> foreach 1.5.2 2022-02-02 [1] CRAN (R 4.3.0)
#> fs 1.6.3 2023-07-20 [1] CRAN (R 4.3.0)
#> generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0)
#> GenomeInfoDb 1.38.5 2023-12-28 [1] Bioconductor 3.18 (R 4.3.2)
#> GenomeInfoDbData 1.2.11 2024-01-22 [1] Bioconductor
#> ggplot2 * 3.4.4 2023-10-12 [1] CRAN (R 4.3.0)
#> glue 1.7.0 2024-01-09 [1] CRAN (R 4.3.0)
#> gtable 0.3.4 2023-08-21 [1] CRAN (R 4.3.0)
#> highr 0.10 2022-12-22 [1] CRAN (R 4.3.0)
#> htmltools 0.5.7 2023-11-03 [1] CRAN (R 4.3.0)
#> igraph 1.6.0 2023-12-11 [1] CRAN (R 4.3.0)
#> IRanges 2.36.0 2023-10-24 [1] Bioconductor
#> iterators 1.0.14 2022-02-05 [1] CRAN (R 4.3.0)
#> jsonlite 1.8.8 2023-12-04 [1] CRAN (R 4.3.0)
#> knitr 1.45 2023-10-30 [1] CRAN (R 4.3.0)
#> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.3.0)
#> lattice 0.22-5 2023-10-24 [1] CRAN (R 4.3.0)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.3.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0)
#> MASS 7.3-60.0.1 2024-01-13 [1] CRAN (R 4.3.0)
#> Matrix 1.6-5 2024-01-11 [1] CRAN (R 4.3.0)
#> mgcv 1.9-1 2023-12-21 [1] CRAN (R 4.3.0)
#> microbiome 1.24.0 2023-10-24 [1] Bioconductor
#> microViz * 0.12.1 2024-01-25 [1] local
#> multtest 2.58.0 2023-10-24 [1] Bioconductor
#> munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0)
#> nlme 3.1-164 2023-11-27 [1] CRAN (R 4.3.0)
#> permute 0.9-7 2022-01-27 [1] CRAN (R 4.3.0)
#> phyloseq 1.46.0 2023-10-24 [1] Bioconductor
#> pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0)
#> plyr 1.8.9 2023-10-02 [1] CRAN (R 4.3.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.3.0)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.3.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.3.0)
#> R.oo 1.25.0 2022-06-12 [1] CRAN (R 4.3.0)
#> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.3.0)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0)
#> Rcpp 1.0.12 2024-01-09 [1] CRAN (R 4.3.0)
#> RCurl 1.98-1.14 2024-01-09 [1] CRAN (R 4.3.0)
#> registry 0.5-1 2019-03-05 [1] CRAN (R 4.3.0)
#> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.3.0)
#> reshape2 1.4.4 2020-04-09 [1] CRAN (R 4.3.0)
#> rhdf5 2.46.1 2023-11-29 [1] Bioconductor
#> rhdf5filters 1.14.1 2023-11-06 [1] Bioconductor
#> Rhdf5lib 1.24.1 2023-12-12 [1] Bioconductor 3.18 (R 4.3.2)
#> rlang 1.1.3 2024-01-10 [1] CRAN (R 4.3.0)
#> rmarkdown 2.25 2023-09-18 [1] CRAN (R 4.3.0)
#> rstudioapi 0.15.0 2023-07-07 [1] CRAN (R 4.3.0)
#> Rtsne 0.17 2023-12-07 [1] CRAN (R 4.3.0)
#> S4Vectors 0.40.2 2023-11-23 [1] Bioconductor
#> scales 1.3.0 2023-11-28 [1] CRAN (R 4.3.0)
#> seriation 1.5.4 2023-12-12 [1] CRAN (R 4.3.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0)
#> stringi 1.8.3 2023-12-11 [1] CRAN (R 4.3.0)
#> stringr 1.5.1 2023-11-14 [1] CRAN (R 4.3.0)
#> styler 1.10.2 2023-08-29 [1] CRAN (R 4.3.0)
#> survival 3.5-7 2023-08-14 [1] CRAN (R 4.3.2)
#> tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0)
#> tidyr 1.3.1 2024-01-24 [1] CRAN (R 4.3.2)
#> tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0)
#> TSP 1.2-4 2023-04-04 [1] CRAN (R 4.3.0)
#> utf8 1.2.4 2023-10-22 [1] CRAN (R 4.3.0)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.3.0)
#> vegan 2.6-4 2022-10-11 [1] CRAN (R 4.3.0)
#> withr 3.0.0 2024-01-16 [1] CRAN (R 4.3.0)
#> xfun 0.41 2023-11-01 [1] CRAN (R 4.3.0)
#> xml2 1.3.6 2023-12-04 [1] CRAN (R 4.3.0)
#> XVector 0.42.0 2023-10-24 [1] Bioconductor
#> yaml 2.3.8 2023-12-11 [1] CRAN (R 4.3.0)
#> zlibbioc 1.48.0 2023-10-24 [1] Bioconductor
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
#>
#> ────────────────────────────────────────────────────────────────────────────── |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
loving this package - especially since I am new(ish) to R and ggplot can be hard to navigate. I am hoping someone can give me some advice about the x-axis label.
I am following the walkthrough on dominant taxa barplots (https://david-barnett.github.io/microViz/reference/ps_calc_dominant.html) and I wanted to add a second x-axis label. At the moment I am selecting either to label the x axis with "dominant_Genus" or "subject id".
I would like to be able to display the most abundant taxa on the x-axis but also want to display the subject id, either, next to it, on a secondary x-axis or as an annotation on the stacked bar - however I have had no luck with ggplot.
Can anyone propose any suggestions that do not require me to look too deeply under the bonnet of ggplot to get it to work?
Thanks
Rachele
Beta Was this translation helpful? Give feedback.
All reactions