KasperSkytte / ampvis2

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

About to know_Can I change the color in the ordination plots #153

Closed isuvodeep closed 1 year ago

isuvodeep commented 1 year ago

Hi, I would like to know Can I change the colors of any specific variable that I want to represent in the ordination plots? For an NMDS/PCA/PCoA, I mentioned a constraint, and I used the function, sample_color_by = "my variable", for the specific parameters that I want to look at based on their ordination. Everyone in the guidelines, talked about the sample_color_by option, but if I want to choose a specific color, how to do that?

KasperSkytte commented 1 year ago

Hi there.

The plotting functions return a ggplot2 object, so you can always customize it to your likings using standard ggplot2 functions. Adjust the colors by adjusting the scale, see https://ggplot2.tidyverse.org/reference/index.html#scales, or manually for example:

library(ampvis2)
#> Loading required package: ggplot2
plot <- amp_ordinate(
  AalborgWWTPs,
  sample_color_by = "Plant"
)
#> 8628 OTUs not present in more than 0.1% relative abundance in any sample have been filtered 
#> Before: 9430 OTUs
#> After: 802 OTUs
plot

plot + scale_color_manual(values = c("red", "green"))

Created on 2023-03-14 with reprex v2.0.2