2012-03-28 5 views
4

나는 교육적인 예로서 해양 생물학 과정을위한 간단한 계통 발생 수목을 만들고 싶다. 나는 분류 학적 순위와 종의 목록을 가지고 :종의 목록에서 간단한 계통 발생 계통도 (나무) 만들기

Group <- c("Benthos","Benthos","Benthos","Benthos","Benthos","Benthos","Zooplankton","Zooplankton","Zooplankton","Zooplankton", 
"Zooplankton","Zooplankton","Fish","Fish","Fish","Fish","Fish","Fish","Phytoplankton","Phytoplankton","Phytoplankton","Phytoplankton") 
Domain <- rep("Eukaryota", length(Group)) 
Kingdom <- c(rep("Animalia", 18), rep("Chromalveolata", 4)) 
Phylum <- c("Annelida","Annelida","Arthropoda","Arthropoda","Porifera","Sipunculida","Arthropoda","Arthropoda","Arthropoda", 
"Arthropoda","Echinoidermata","Chorfata","Chordata","Chordata","Chordata","Chordata","Chordata","Chordata","Heterokontophyta", 
"Heterokontophyta","Heterokontophyta","Dinoflagellata") 
Class <- c("Polychaeta","Polychaeta","Malacostraca","Malacostraca","Demospongiae","NA","Malacostraca","Malacostraca", 
"Malacostraca","Maxillopoda","Ophiuroidea","Actinopterygii","Chondrichthyes","Chondrichthyes","Chondrichthyes","Actinopterygii", 
"Actinopterygii","Actinopterygii","Bacillariophyceae","Bacillariophyceae","Prymnesiophyceae","NA") 
Order <- c("NA","NA","Amphipoda","Cumacea","NA","NA","Amphipoda","Decapoda","Euphausiacea","Calanioda","NA","Gadiformes", 
"NA","NA","NA","NA","Gadiformes","Gadiformes","NA","NA","NA","NA")      
Species <- c("Nephtys sp.","Nereis sp.","Gammarus sp.","Diastylis sp.","Axinella sp.","Ph. Sipunculida","Themisto abyssorum","Decapod larvae (Zoea)", 
"Thysanoessa sp.","Centropages typicus","Ophiuroidea larvae","Gadus morhua eggs/larvae","Etmopterus spinax","Amblyraja radiata", 
"Chimaera monstrosa","Clupea harengus","Melanogrammus aeglefinus","Gadus morhua","Thalassiosira sp.","Cylindrotheca closterium", 
"Phaeocystis pouchetii","Ph. Dinoflagellata") 
dat <- data.frame(Group, Domain, Kingdom, Phylum, Class, Order, Species) 
dat 

가 나는 dendrogram은 (클러스터 분석)를 얻을 첫 번째 절단 점으로 도메인을 사용하고자하는, Kindom 두 번째로, 문 등, 세 번째로 누락 값을 무시해야합니다 (절단 점이없는 대신 직선). 그룹은 라벨의 색상 카테고리로 사용해야합니다.

이 데이터 프레임에서 거리 매트릭스를 만드는 방법에 대해서는 조금 확신이 없습니다. R에 대한 많은 계통 발생 트리 패키지가 있으며, 그들은 newick 데이터/DNA/기타 고급 정보를 원한다. 따라서이 도움은 인정 될 것입니다. (이것은 완전한 대답하지 당신이 (이 아마 그것을 할 수있는 가장 좋은 방법이 아니다) 손 으로 을 다음과 같이 시작할 수 를 트리를 그리는 원한다면

+0

) = 그것은 무언가를 찾아 주 소요 R.으로 작업 흐름을 보여줍니다 . – Joel

+0

'r-sig-phylo @ r-project.org'에서이 질문에 대한 더 유용한 도움을 얻을 수 있습니다 ... –

+0

음 ... plot.hclust()는 훌륭한 플롯을 생성합니다. 확실히이 데이터 세트를 hclust 객체로 변환하는 방법이 있어야합니까? ade4 패키지 plot.phylog (http://pbil.univ-lyon1.fr/ade4/ade4-html/plot.phylog.html)는 더 좋은 것들을 만들지 만, 아마도이 데이터 프레임을 phylog 객체로 바꾸는 것은 불가능할 것입니다 (http : /pbil.univ-lyon1.fr/ade4/ade4-html/phylog.html)? – Mikko

답변

3

아마도 내 자신의 질문에 답하는 것은 조금 불편할 지 모르겠지만 더 쉬운 해결책을 찾았습니다. 어쩌면 어느 날 누군가를 도울 수 있습니다.

library(ape) 
taxa <- as.phylo(~Kingdom/Phylum/Class/Order/Species, data = dat) 

col.grp <- merge(data.frame(Species = taxa$tip.label), dat[c("Species", "Group")], by = "Species", sort = F) 

cols <- ifelse(col.grp$Group == "Benthos", "burlywood4", ifelse(col.grp$Group == "Zooplankton", "blueviolet", ifelse(col.grp$Group == "Fish", "dodgerblue", ifelse(col.grp$Group == "Phytoplankton", "darkolivegreen2", "")))) 

plot(taxa, type = "cladogram", tip.col = cols) 

모든 열은 요인이어야합니다. 코드 자체가 행의 단지 몇 있지만 문제는 복잡 소리 똑똑한 사람들의 관심을 필요로이 투표까지-

enter image description here

+0

그러나 줄에 색상을 지정하는 방법을 궁금해합니다. 가장자리는 레이블 이름을 기반으로 색상을 제어하는 ​​것이 어렵다는 방식으로 할당 된 것 같습니다. – Mikko

3

: 색상 누락, 을하고있다 가장자리가 너무 깁니다.) 이것은 데이터가 이미 정렬되었다고 가정합니다.

# Data: remove Group 
dat <- data.frame(Domain, Kingdom, Phylum, Class, Order, Species) 

# Start a new plot 
par(mar=c(0,0,0,0)) 
plot(NA, xlim=c(0,ncol(dat)+1), ylim=c(0,nrow(dat)+1), 
    type="n", axes=FALSE, xlab="", ylab="", main="") 

# Compute the position of each node and find all the edges to draw 
positions <- NULL 
links <- NULL 
for(k in 1:ncol(dat)) { 
    y <- tapply(1:nrow(dat), dat[,k], mean) 
    y <- y[ names(y) != "NA" ] 
    positions <- rbind(positions, data.frame(
    name = names(y), 
    x = k, 
    y = y 
)) 
} 
links <- apply(dat, 1, function(u) { 
    u <- u[ !is.na(u) & u != "NA" ] 
    cbind(u[-length(u)],u[-1]) 
}) 
links <- do.call(rbind, links) 
rownames(links) <- NULL 
links <- unique(links[ order(links[,1], links[,2]), ]) 

# Draw the edges 
for(i in 1:nrow(links)) { 
    from <- positions[links[i,1],] 
    to <- positions[links[i,2],] 
    lines(c(from$x, from$x, to$x), c(from$y, to$y, to$y)) 
} 

# Add the text 
text(positions$x, positions$y, label=positions$name) 
+0

코드 주셔서 감사합니다! 그러나 나는이 해결책에 완전히 만족하지 않는다. 어쩌면 이것을 할 수있는 더 쉬운 방법이있을 것입니다. – Mikko