I am currently struggling with scale_color_manual in ggplot2, although this has never been a problem. I keep getting the error message: "Error: Insufficient values in manual scale. 9 needed but only 0 provided." However, I have clearly provided enough colors, so it just doesn't seem to be registering. Does anyone know what is going on/how I can fix this?
My ggplot2 package version is: 3.3.3. Phyloseq Version is 1.30.0
library(phyloseq)
library(ggplot2)
data("GlobalPatterns")
GP <- prune_species(speciesSums(GlobalPatterns) > 0, GlobalPatterns)
#this usually works to assign colors below
cohortcol<- c("#70AD47","orange", "blue", "green","red",
"yellow","purple","black","grey")
a<-plot_richness(GP, x="SampleType", color="SampleType",
measures=c("Chao1", "Shannon")) +
scale_color_manual(values=alpha(cohortcol, 0.7)) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
legend.position="none", axis.title.y = element_blank())
print(a)
It then doesn't print a and gives me my error message. I get the same message if I were to remove cohortcol and just add colors as a vector instead instead.
GP is a phyloseq object.
Restarting R used to do the trick, however, even this has stopped working now.
Thanks for your help!
You need to provide names to the
cohortcol
so thatggplot2
would know which color matching with what values in the dataYour code should work fine if you do this
Here is the full working code. I didn't use phyloseq much but there are multiple warning about deprecated function in your code, pay attention to that too.
Created on 2021-05-01 by the reprex package (v2.0.0)