KasperSkytte / ampvis2

Tools for visualising microbial community amplicon data
https://kasperskytte.github.io/ampvis2/
GNU General Public License v3.0
67 stars 24 forks source link

Edit taxa labels in amp_heatmap plot #140

Closed msmcfarlin closed 2 years ago

msmcfarlin commented 2 years ago

Hello,

I am using amp_heatmap and I was curious if there was a way to edit the y-axis labels for taxa. My plot below is aggregated at the Family level and I would like to remove the ASV labels for taxa that were missing Family labels and were fit to the best taxonomic classification possible, i.e. "c__Actinobacteria_8f9e5b675bcf336f6b03c43328eee513"

image

Thank you!

KasperSkytte commented 2 years ago

Hi

Maybe have a look at the tax_empty argument. But to edit the labels you can either replace the names in the $data data frame in the ggplot object or you can set the labels manually using standard ggplot scales, I think scale_y_discrete() is what you would need for a heatmap.

msmcfarlin commented 2 years ago

Hi @KasperSkytte,

I had some issues plotting after replacing the names in the $data data frame but using scale_y_discrete() worked great!

Thank you!

KasperSkytte commented 2 years ago

Great. Feel free to share the code here for others who might have the same problem.

msmcfarlin commented 2 years ago

Sure! Here's the code I used to edit the labels.

Note that in the first code chunk I made the heatmap with amp_heatmap(), then in the second chunk I edited the plot and used the labels in scale_y_discrete() to edit the taxa names.

heatmap.plot <- 
         amp_heatmap(fam.subset,
                  group_by = "Colony",
                  facet_by = "Species",
                  tax_show = 18,
                  tax_aggregate = "Family",
                  tax_empty = "best",
                  normalise = F,
                  color_vector = c("royalblue4",
                         "whitesmoke",
                         "darkred"),
                  plot_colorscale = "log10",
                  plot_values = T,
                  min_abundance = 0.001,
                  round = 2,
                  measure = "mean")
edited.plot <- 
                heatmap.plot +
                theme(axis.text.x = element_text(angle = 0, size= 11, vjust = 1, hjust = .5),
                      axis.text.y = element_text(size=11),
                      legend.position="none") +
                scale_y_discrete(labels = c("o__Frankiales_8feadc7d5554ac77717f0f66d08c38b7" = "O. Frankiales",
                                            "c__Actinobacteria_8f9e5b675bcf336f6b03c43328eee513" = "C. Actinobacteria",
                                            "c__Gammaproteobacteria_dcc7088c11a96cd6624543f6c2c18abd" = "C. Gammaproteobacteria",
                                            "Gracilibacteria" = "C. Gracilibacteria",
                                            "Subgroup_7" = "C. Holophagae Subgroup 7"))
edited.plot

image