Open sumitra20 opened 2 years ago
Hi! You would just need to add two more colours to scale_colour_manual(). Only 2 are listed now, and you would need 4 for your data.
e.g.
scale_colour_manual(values = c("#009E73", "#E69F00", "red", "blue"))
Hi @jkzorz,
My apologies, seem to have another question. I have 3 different groups (day, yield, season) that i would like to analyze, will i be able to plot more than 2 groups with NDMS plot? Not sure how to edit the line below:
data.scores$Sample = pc$Sample
data.scores$Time = pc$Day
data.scores$Type = pc$Yield
data.scores$Season = pc$Season
xx = ggplot(data.scores, aes(x = NMDS1, y = NMDS2)) +
geom_point(size = 4, aes( shape = as.factor(Type,Season), colour = as.factor(Time)))+
theme(axis.text.y = element_text(colour = "black", size = 12, face = "bold"),
axis.text.x = element_text(colour = "black", face = "bold", size = 12),
legend.text = element_text(size = 12, face ="bold", colour ="black"),
legend.position = "right", axis.title.y = element_text(face = "bold", size = 14),
axis.title.x = element_text(face = "bold", size = 14, colour = "black"),
legend.title = element_text(size = 14, colour = "black", face = "bold"),
panel.background = element_blank(), panel.border = element_rect(colour = "black", fill = NA, size = 1.2),
legend.key=element_blank()) +
labs(x = "NMDS1", colour = as.factor("Time"), y = "NMDS2", shape = as.factor("Type","Season")) +
scale_colour_manual(values = c("#009E73", "#E69F00", "#F0E442","#AA4499"))
This is the rror i get from running above:
Error in geom_point()
:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in as.factor()
:
! unused argument (Season)
And if thats not possible, can i plot for each of my groups separately, one for yield (high vs low), day (0,30,60,90), season (1,2,3)?
Thank you so much in advance
Hi!
Yes you can plot/differentiate all three groups on the same figure, you just need to map a different aesthetic to each group. So in the case above, "colour" is mapped to Time, and "shape" is mapped to Type. You need to map Season to a different aesthetic, for instance "size" or "alpha".
e.g.
geom_point(size = 4, aes( shape = as.factor(Type), size = Season, colour = as.factor(Time)))
Now whether or not this is something you want to do is another question. Trying to convey three different variables on the same plot can be difficult for the viewer. You may want to play around with what variable you map to which aesthetic.
You can plot each variable separately but you would have to create 3 different plots.
Hope this helps!
Hi @jkzorz ,
Im very new to bioinformatic and R and im trying to replicate the tutorial you posted on 'https://jkzorz.github.io/2019/06/06/NMDS.html' to get NDMS plot for my data. This is my sample dataframe:
and the code:
But i got an error msg that said 'Error: Continuous value supplied to discrete scale'
Then i tried editing by setting color and shape to factor:
Ended up with another error Error in
f()
:! Insufficient values in manual scale. 4 needed but only 2 provided.Not sure where im going wrong and on how to rectify it. Did really appreciate it if you could help. Thank you in advance