Skip to content

Can I do sampleAnnotation() to comp_barplot object as in comp_heatmap? #65

Answered by david-barnett
Stray357 asked this question in Q&A
Discussion options

You must be logged in to vote

here is a somewhat hacky way to do this for one sample variable

library(microViz)
library(ggplot2)
library(dplyr)
data(dietswap, package = "microbiome")

# how to add coloured segments to the left of (or underneath) stacked bars
dietswap %>%
  ps_filter(timepoint == 1) %>% 
  comp_barplot(
    tax_level = "Genus", n_taxa = 15, other_name = "Other",
    taxon_renamer = function(x) stringr::str_remove(x, " [ae]t rel."),
    palette = distinct_palette(n = 15, add = "grey90"),
    merge_other = FALSE, bar_outline_colour = "darkgrey"
  ) +
  geom_segment(
    mapping = aes(colour = nationality, xend = SAMPLE), # colour, but not fill
    data = ~ dplyr::distinct(., SAMPLE, .keep_all = TRUE), # …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Stray357
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants