Thanks a lot Gwen! Now I have a follow up question. Imagine you want to connect 
tips of your phylogeny to locations on a map where they were found all in one 
figure. Using your code for the tip coords I can set up the figure but can't 
seem to get the lines to attach. Do you or anyone else have any ideas? Thanks!!

here's the code:

# Create a phylogeny
library(phytools)
tree <- pbtree(n=10)
plot(tree)

# Create coordinates where species at tips of phylogeny were found
species <- tree$tip.label
lat <- c(51, 18.3, -35.9, 36.46, 32.71, 41.9, 29.82, 34.6, 19.89, 49.88)
lon <- c(9, -47.5, -83.9, 127.62, -117.16, 12.5, 25.35, -58.4, -43.95, -97.15)
dat <- data.frame(species, lat, lon)

# Get a Map
library(rworldmap)
map <- getMap(resolution="low")

# Start Plot
par(fig=c(0,1,0,0.7), new=TRUE)
plot(map) # always comes out a bit small compared to the tree
points(dat$lon, dat$lat, pch=16, cex=1, col="red")
par(fig=c(0,1,0.7,1), new=TRUE)
plot(tree, direction="downward", no.margin=TRUE)
lastPP <- get("last_plot.phylo", envir = .PlotPhyloEnv)
tip <- 1:lastPP$Ntip
XX <- lastPP$xx[tip] # x coordinates for phylo tree tips
YY <- lastPP$yy[tip] # y coordinates for phylo tree tips
lines(c(XX,dat$lon),c(YY,dat$lat)) # lines don't connect here




        [[alternative HTML version deleted]]

_______________________________________________
R-sig-phylo mailing list - [email protected]
https://stat.ethz.ch/mailman/listinfo/r-sig-phylo
Searchable archive at http://www.mail-archive.com/[email protected]/

Reply via email to