Hi Tony.
A couple of additional shortcuts would be:
# name rows of data frame with first column
> anolis.dat<-read.csv("anolis_data.csv",row.names=1)
# sort rows by $tip.label
> anolis.dat<-anolis.dat[anolisChrono$tip.label,]
# then
> attach(anolis.dat)
> plot(anolisChrono,adj=0.5, cex=0.4)
# after "attaching" anolis.dat you can just call "micro" directly
> tiplabels(micro,frame="none", bg="white", adj=0.1, cex=0.4)
--
Liam J. Revell
University of Massachusetts Boston
web: http://faculty.umb.edu/liam.revell/
(new) email: liam.rev...@umb.edu
(new) blog: http://phytools.blogspot.com
On 2/27/2011 1:00 PM, Rich Glor wrote:
Tony,
The problem is that tiplabels just throws up the labels in the same order as
they appear in the matrix of data you're calling (i.e., anolisData). The first
entry in the the data matrix will therefore be associated with the first taxon
in your tree. This might not be obvious at first, but recall that tip #1 in
your tree is the one at the bottom of the plotting window, not the top. Note
that the sequence of micro labels in your plot is in the same sequence as in
the anolisData matrix: tip #1 in your tree (evermanni) has micro=1 and tip #2
(stratulus) has micro=5, etc., matching the sequence in the anolisData matrix.
One way to fix this is to use the matching function to reorder the data in
anolisData so that it matches up with the order of the taxa in your tree:
match(anolisChrono$tip.label, rownames(anolisData)) -> match
anolisData[,][match,] -> sortedData
plot(anolisChrono,show.node.label=FALSE, adj=0.5, cex=0.4);
tiplabels(sortedData[,1],frame="none", bg="white", adj=0.1, cex=0.7)
Hope this helps,
Rich
On Feb 27, 2011, at 12:30 PM, Tony Gamble wrote:
Hello,
I am having a problem matching data and tip.labels when I plot trait data on a
phylogeny. I open the tree and data in R and convert the data to a dataframe
and then assign taxon names from the tree to the values in the dataframe. When
I simply print the dataframe the taxon names and data properly match up. Using
the name.check function confirms that the taxon names in the tree match the
taxon names in the dataframe. The problem occurs when I plot the tree and label
the tips with both taxon names and the trait values. The taxon names are
correctly placed onto the tree but the traits are not properly assigned to the
tips. Any ideas on how to fix this?
Thanks!
Tony
Details:
I'm using R version 2.12.2 and APE 2.6-3.
The example below is based on the the sample data from the Bodega Bay tutorial
but I've run into the same problem with my own datasets.
The tree and data files can be found here:
https://netfiles.umn.edu/users/gambl007/figures_2011/anolisComparativeTree.tre
http://bodegaphylo.wikispot.org/Phylogenetics_and_Comparative_Methods_in_R?action=Files&do=view&target=anolis_data.csv
anolisChrono<-read.tree("anolisComparativeTree.tre");
anolis.dat<-read.csv("anolis_data.csv");
anolisData<-data.frame(anolis.dat[,2:3]);
rownames(anolisData)<- anolis.dat[,1];
attach(anolisData);
names(micro)<- anolisChrono$tip.label;
names(SVL)<- anolisChrono$tip.label;
name.check(anolisChrono, anolisData);
[1] "OK"
anolisData;
micro SVL
ahli 1 61.7
alayoni 5 46.8
alfaroi 0 36.0
aliniger 3 57.0
allisoni 3 75.0
allogus 1 62.8
altitudinalis 3 52.0
alumina 0 40.0
alutaceus 0 37.0
angusticeps 5 44.8
armouri 1 67.0
bahorucoensis 0 51.0
baleatus 4 180.0
baracoae 4 172.0
barahonae 4 160.0
bremeri 1 72.0
breslini 1 61.5
brevirostris 2 50.0
caudalis 2 48.0
chlorocyanus 3 76.0
clivicola 0 49.0
coelestinus 3 84.0
confusus 1 53.0
cooki 1 70.0
cristatellus 1 75.0
cupeyalensis 0 33.0
cuvieri 4 122.0
cyanopleurus 0 43.0
cybotes 1 77.0
darlingtoni 5 72.0
distichus 2 58.0
dolichocephalus 0 52.0
equestris 4 188.0
evermanni 3 70.0
garmani 4 131.0
garridoi 5 41.8
grahami 3 75.0
guafe 1 48.8
guazuma 5 48.5
gundlachi 1 68.0
haetianus 1 75.0
hendersoni 0 49.0
homolechis 1 70.0
imias 1 65.0
inexpectatus 0 37.0
insolitus 5 47.0
isolepis 3 52.0
jubar 1 62.0
krugi 0 45.0
lineatopus 1 70.0
longitibialis 1 72.0
loysiana 2 40.0
luteogularis 4 191.0
macilentus 0 41.0
marcanoi 1 57.0
marron 2 50.0
mestrei 1 56.0
noblei 4 190.0
occultus 5 42.0
olssoni 0 50.0
opalinus 3 53.0
ophiolepis 0 35.0
oporinus 3 47.0
paternus 5 50.0
placidus 5 46.0
poncensis 0 44.0
porcatus 3 73.0
pulchellus 0 47.0
quadriocellifer 1 55.0
rejectus 0 37.0
ricordii 4 160.0
rubribarbus 1 58.0
sagrei 1 70.0
semilineatus 0 40.0
sheplani 5 41.0
shrevei 1 60.0
singularis 3 45.0
smallwoodi 4 190.0
strahmi 1 79.0
stratulus 3 44.0
tranquillus 5 45.0
valencienni 5 80.0
vanidicus 0 39.0
websteri 2 51.0
whitemani 1 67.0
plot(anolisChrono,show.node.label=FALSE, adj=0.5, cex=0.4);
tiplabels(anolisData$micro,frame="none", bg="white", adj=0.1, cex=0.4)
I've put the tree plot here - A quick comparison to the dataframe above shows that the
"micro" data do not match up to the correct tips and taxa:
https://netfiles.umn.edu/users/gambl007/figures_2011/Anolis_R_tree_characters.pdf
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
[[alternative HTML version deleted]]
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
_______________________________________________
R-sig-phylo mailing list
R-sig-phylo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo