2017-09-26 61 views
1

在系统发育扇中,我想通过应用if语句对提示进行颜色编码(类似本例中的62种)。我目前使用下面的代码,试图以色彩搭配“O”深绿相关联的所有种类:将ifelse函数应用于系统发育扇的颜色提示

ColourIf = ifelse(LU != "O", "blue", "darkgreen") 

tiff("PhyloFan.tif", height=10, width=10, units="in", res=300, compression="lzw"); 
plot.phylo(phyloFan,type="fan",show.tip.label=T,cex=0.9,show.node.label=F, 
      edge.color="black", adj=0, label.offset=0.75, lwd=2, edge.width=1, 
      tip.color=ColourIf) 
par(oma=c(0,0,0,0))  
dev.off() 

目前,七种颜色为绿色(号码是正确的),但相关的不是那些数据表中的“O”。如何修改代码,以便正确的七种物种以绿色显示(即cropoi,diomal,garsoo,holpub,phycol,stegut,steneu)?

这是我产生了目前的数字:

enter image description here

提前任何建议非常感谢。

这是可再生的数据:dput(LU)

structure(list(LU = structure(c(1L, 3L, 1L, 1L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 1L, 3L, 3L, 
3L, 3L, 4L, 1L, 3L, 3L, 4L, 3L, 3L, 1L, 3L, 3L, 3L, 2L, 3L, 3L, 
3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 3L, 
3L, 3L, 1L, 1L, 3L, 3L), .Label = c("H", "L", "na", "O"), class = "factor")), .Names = "LU", class = "data.frame", row.names = c("albleb", 
"albodo", "antgha", "apovil", "artlak", "briret", "buclan", "cansub", 
"carsph", "catspa", "cropoi", "dalcul", "dallan", "dalnig", "daloli", 
"dilobo", "dioehr", "diomal", "dipint", "diptub", "elltom", "erican", 
"erysuc", "flesoo", "garcow", "garobt", "garsoo", "gmearb", "greeri", 
"halcor", "holpub", "irvoli", "lancor", "lopdup", "mancal", "memedu", 
"memscu", "milleu", "mitrot", "morcor", "ochint", "parama", "pavtom", 
"permem", "phycol", "phyemb", "ptemac", "rotwit", "schole", "shoobt", 
"shorox", "shosia", "sinsia", "stegut", "steneu", "strnux", "symrac", 
"syz001", "terala", "tercal", "terche", "xylxyl")) 

这newick文件保存phyloFan信息:

(((((((((((((((((((((((((((((shosia:15.089286,shoobt:15.089286,shorox:15.089286)shorea:15.089286,(dipint:15.089286,diptub:15.089286)dipterocarpus:15.089286)dipterocarpaceae:15.089285):15.089287):15.089283,((stegut:25.148809)sterculia:25.148809,(erican:25.148809)eriolaena:25.148809,(greeri:25.148809)grewia:25.148809)malvaceae:25.148808):15.089287):15.089287)malvales:15.089287)malvales_to_brassicales:15.089287)huerteales_to_brassicales:15.089279,(((((((buclan:18.861607)buchanania:18.861607,(lancor:18.861607)lannea:18.861607,(mancal:18.861607)mangifera:18.861607)anacardiaceae:18.861607,((cansub:18.861607)canarium:18.861607)burseraceae:18.861607):18.861607):18.861603,(((schole:23.577007)schleichera:23.577007)sapindaceae:23.577003):23.577011):18.861610):18.861610)sapindales:18.861603):15.089294):15.089279):15.089294,(((((((memedu:24.520090,memscu:24.520090)memecylon:24.520090)melastomataceae:24.520092):24.520088,(((syz001:24.520090)syzygium:24.520090)myrtaceae:24.520092):24.520088):24.520088):24.520096,((terala:49.040180,tercal:49.040180,terche:49.040180)terminalia:49.040180)combretaceae:49.040184)myrtales:24.520081):24.520096)malvids:15.089279,(((((((sinsia:81.250000)sindora:81.250000,(((((((((((erysuc:29.791666)erythrophleum:29.791666)dimorphandra_group:29.791668,((((((((((albleb:8.125000,albodo:8.125000)albizia:8.125000)ingeae:8.125000):8.125000):8.125000):8.125000):8.125000):8.125000):8.125000,((xylxyl:24.375000)xylia:24.375000)adenanthera_group:24.375000):8.125000):8.125000)mimosoids:8.125000):8.125000):8.125000):8.125000):8.125000):8.125000,((((((((((((((((flesoo:8.125000)flemingia:8.125000)cajaninae:8.125000):8.125000):8.125000):8.125000)phaseoloids:8.125000):8.125000):8.125000):8.125000):8.125000):8.125000,((((((((ptemac:10.833333)pterocarpus:10.833333):10.833334):10.833332)pterocarpus_group:10.833336,(((dalcul:13.541667,dallan:13.541667,dalnig:13.541667,daloli:13.541667)dalbergia:13.541667):13.541666)dalbergia_group:13.541668):10.833332)dalbergieae:10.833336):10.833328):10.833336):8.125000):8.125000):8.125000):8.125000)papilionoideae:8.125000):8.125000):8.125000):8.125000,(milleu:81.250000)millettia:81.250000)fabaceae:8.125000):8.125000)fabales:8.125000,(((((((((((artlak:15.572917)artocarpus:15.572917):15.572916):15.572918):15.572918)moraceae:15.572914):15.572914):15.572922):15.572914):15.572922)rosales:15.572906):15.572922):8.125000,((((((cropoi:32.500000)croton:32.500000,(phycol:32.500000,phyemb:32.500000)phyllanthus:32.500000,(antgha:32.500000)antidesma:32.500000,(apovil:32.500000)aporusa:32.500000,(briret:32.500000)bridelia:32.500000)euphorbiaceae:32.500000):32.500000,((irvoli:43.333332)irvingia:43.333332)irvingiaceae:43.333336,((((garcow:26.000000)garcinia:26.000000)clusiaceae:26.000000):26.000000):26.000000,((ochint:43.333332)ochna:43.333332)ochnaceae:43.333336,(((((parama:21.666666)parinari:21.666666)chrysobalanaceae:21.666668):21.666664):21.666672):21.666664)malpighiales:21.666672,(((((elltom:25.277779)ellipanthus:25.277779)connaraceae:25.277779):25.277779):25.277779)oxalidales:25.277779):21.666656,(((lopdup:43.333332)lophopetalum:43.333332)celastraceae:43.333336)celastrales:43.333328)celastrales_to_malpighiales:21.666672):8.125000)fabids:8.125000):8.125000)rosids:8.125000):8.125000,(((((((((carsph:45.518467)careya:45.518467)lecythidaceae:45.518471,(((((symrac:22.759233)symplocos:22.759233)symplocaceae:22.759235):22.759232):22.759232,((((dioehr:22.759233,diomal:22.759233)diospyros:22.759233)ebenaceae:22.759235):22.759232):22.759232):22.759239):22.759232)ericales:22.759232,((((((catspa:63.437496)catunaregam:63.437496,((((((((((pavtom:11.534090)pavetta:11.534090):11.534092):11.534088,(((garobt:11.534090,garsoo:11.534090)gardenia:11.534090):11.534092):11.534088):11.534092):11.534092):11.534088):11.534088):11.534096)ixoroideae:11.534088):11.534088,(rotwit:63.437496)rothmannia:63.437496,(halcor:63.437496)haldina:63.437496,(mitrot:63.437496)mitragyna:63.437496,((((((morcor:18.124998)morinda:18.124998):18.125000):18.124996):18.125000):18.125000)rubioideae:18.125000)rubiaceae:11.534096,((((strnux:30.757576)strychnos:30.757576)loganiaceae:30.757576,(((holpub:23.068182)holarrhena:23.068182)apocynaceae:23.068180):23.068184):23.068176):23.068184)gentianales:11.534088,(((((((((((((steneu:10.710227)stereospermum:10.710227)bignoniaceae:10.710226):10.710228):10.710228,(((gmearb:13.387784)gmelina:13.387784)lamiaceae:13.387785):13.387783):10.710224):10.710228):10.710228):10.710228):10.710228):10.710228):10.710220)lamiales:10.710236):10.710220):10.710236)lamiids:10.710220):10.710236)ericales_to_asterales:10.710220)asterids:10.710236):10.710220):10.710236):10.710220,((dilobo:78.541664)dillenia:78.541664)dilleniaceae:78.541672):8.125000)core_eudicots:8.125000)trochodendrales_to_asterales:8.125000)sabiales_to_asterales:8.125000)eudicots:8.125000)ceratophyllales_and_eudicots:8.125000)poales_to_asterales:8.125000,(((((((((permem:29.250000)persea:29.250000)lauraceae:29.250000):29.250000):29.250000):29.250000)laurales:29.250000):29.250000)magnoliids:29.250000):29.250000)magnoliales_to_asterales:8.125000)austrobaileyales_to_asterales:8.125000)nymphaeales_to_asterales:8.125000)angiosperms:8.125000)seedplants:75.000000)euphyllophyte:1.000000; 

回答

1

您的代码工作正常,但颜色没有下令根据提示标签的顺序(检查phyloFan$tip.label)。用match函数重新排序颜色将解决颜色分配问题。

require(ape) 

# generate a random tree, because importing yours does not work for me 
# skip this step in your code 
set.seed(12345) 
phyloFan <- rtree(n = nrow(LU), tip.label = row.names(LU)) 

# create color vector ordered according to the tip labels 
cols <- ifelse(LU != "O", "blue", "darkgreen")[match(phyloFan$tip.label, row.names(LU))] 

# plot with ordered colors 
plot(phyloFan, type = "fan", tip.color = cols, label.offset = 0.1) 

enter image description here