I’m creating an NMDS ordination plot using R. I’ve shaped points according to sex and coloured by treatment and created ellipses based on sex. But it looks wrong because I’ve realised I’d actually like to create ellipses based on subsets of sex (female vs male) for each treatment subgroup (wheat, rye and barley). How do I modify this code to shape ellipses based on male and female groups upon the different treatments?
This is the code I currently have.
#NMDS ORDINATION PLOT TO SHAPE SEX
#add columns to data frame
site.scrs$sex = Metadata$sex
head(site.scrs)
library(ggplot2)
NMDS_plot2 = ggplot(site.scrs, aes(x = NMDS1, y = NMDS2)) +
geom_point(size = 4, aes( shape = sex, colour = treatment))+
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 = "treatment", y = "NMDS2", shape = "sex") +
scale_colour_manual(values = c("green", "red", "blue","yellow", "orange"))
NMDS_plot2_elipse<-NMDS_plot2+geom_path(data= site.scrs, aes(x=NMDS1,y=NMDS2, colour = sex), size=1, linetype=2)+theme_bw()+annotate("text",x=NMDS.mean$MDS1,y=NMDS.mean$MDS2,label=NMDS.mean$sex)
NMDS_plot2_elipse
New contributor
Marcus Bates is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.