1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| sample <- paste(rep("sample_",24) , seq(1,24) , sep="") specie <- c(rep("dicoccoides" , 8) , rep("dicoccum" , 8) , rep("durum" , 8)) treatment <- rep(c(rep("High",4 ) , rep("Low",4)),3) data <- data.frame(sample,specie,treatment) for (i in seq(1:5)){ gene=sample(c(1:40) , 24 ) data=cbind(data , gene) colnames(data)[ncol(data)]=paste("gene_",i,sep="") } data[data$treatment=="High" , c(4:8)]=data[data$treatment=="High" , c(4:8)]+100 data[data$specie=="durum" , c(4:8)]=data[data$specie=="durum" , c(4:8)]-30 rownames(data) <- data[,1]
dist <- dist(data[ , c(4:8)] , diag=TRUE) hc <- hclust(dist) dhc <- as.dendrogram(hc) specific_leaf <- dhc[[1]][[1]][[1]]
i=0 colLab<<-function(n){ if(is.leaf(n)){ a=attributes(n) ligne=match(attributes(n)$label,data[,1]) treatment=data[ligne,3]; if(treatment=="Low"){col_treatment="blue"};if(treatment=="High"){col_treatment="red"} specie=data[ligne,2]; if(specie=="dicoccoides"){col_specie="red"};if(specie=="dicoccum"){col_specie="Darkgreen"};if(specie=="durum"){col_specie="blue"} attr(n,"nodePar")<-c(a$nodePar,list(cex=1.5,lab.cex=1,pch=20,col=col_treatment,lab.col=col_specie,lab.font=1,lab.cex=1)) } return(n) }
dL <- dendrapply(dhc, colLab) plot(dL , main="structure of the population") legend("topright", legend = c("High Nitrogen" , "Low Nitrogen" , "Durum" , "Dicoccoides" , "Dicoccum"), col = c("red", "blue" , "blue" , "red" , "Darkgreen"), pch = c(20,20,4,4,4), bty = "n", pt.cex = 1.5, cex = 0.8 , text.col = "black", horiz = FALSE, inset = c(0, 0.1))
|