library(randomForest) library(ggtern) ###Set random seed set.seed(678) g1<-read.csv("Morph-rf.csv") dim(g1) g1train=sample(1:nrow(g1),10) Training1.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(12:106), importance = TRUE, proximity = TRUE) Training2.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:11,23:106), importance = TRUE, proximity = TRUE) Training3.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:22,34:106), importance = TRUE, proximity = TRUE) Training4.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:33,45:106), importance = TRUE, proximity = TRUE) Training5.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:44,56:106), importance = TRUE, proximity = TRUE) Training6.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:55,67:106), importance = TRUE, proximity = TRUE) Training7.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:66,77:106), importance = TRUE, proximity = TRUE) Training8.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:76,87:106), importance = TRUE, proximity = TRUE) Training9.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:86,97:106), importance = TRUE, proximity = TRUE) Training10.rf<-randomForest(Ecotype ~ ., data = g1, subset = c(1:96), importance = TRUE, proximity = TRUE) p1<-predict(Training1.rf, g1[1:11,2:8],type = 'vote') p2<-predict(Training2.rf, g1[12:22,2:8],type = 'vote') p3<-predict(Training3.rf, g1[23:33,2:8],type = 'vote') p4<-predict(Training4.rf, g1[34:44,2:8],type = 'vote') p5<-predict(Training5.rf, g1[45:55,2:8],type = 'vote') p6<-predict(Training6.rf, g1[56:66,2:8],type = 'vote') p7<-predict(Training7.rf, g1[67:76,2:8],type = 'vote') p8<-predict(Training8.rf, g1[77:86,2:8],type = 'vote') p9<-predict(Training9.rf, g1[87:96,2:8],type = 'vote') p10<-predict(Training10.rf, g1[97:106,2:8],type = 'vote') ptotal<-rbind(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10) write.csv(ptotal,"ptotal.csv") ptotalid<-read.csv("ptotalid.csv") lines <- data.frame(x = c(0.5, 0, 0.5), y = c(0.5, 0.5, 0), z = c(0, 0.5, 0.5), xend = c(1, 1, 1)/3, yend = c(1, 1, 1)/3, zend = c(1, 1, 1)/3, x1 = c(0.5, 0, 0.5), y1 = c(0.5, 0.5, 0), z1= c(0, 0.5, 0.5), x1end= c(0.5, 0.5, 0), y1end= c(0, 0.5, 0.5), z1end= c(0.5, 0, 0.5)) ggtern(data = ptotalid, aes(CKS, EKS, SIL)) + geom_point(aes(fill = ID), shape = 21, size=2) + geom_segment(data = lines, aes(x, y, z, xend = xend, yend = yend, zend = zend), color = 'black', size = 0.5,lty='dashed') + geom_segment(data = lines, aes(x1, y1, z1, xend = x1end, yend = y1end, zend = z1end), color = 'black', size = 0.5)+ Tlab('Mesic Ecotype') + Rlab("Wet Ecotype") + Llab('Dry Ecotype') + scale_fill_discrete(name = 'Ecotype Identification', labels = c('Dry Ecotype', 'Mesic Ecotype', 'Wet Ecotype')) + theme(legend.position="bottom") ggsave('RF_Phenotype.jpeg',width=7.5,height=7.5,dpi=1200)