liamrevell / phytools

GNU General Public License v3.0
207 stars 56 forks source link

Error when plotting phylo.to.map #6

Open jhill1 opened 8 years ago

jhill1 commented 8 years ago

When plotting phylo to map, I get the following error:

plot(xx,type="phylogram") Error in xy.coords(x, y) : 'x' and 'y' lengths differ

'direct' method works fine.

Some graphics are output, but the tree looks like it needs rotating 180 (see attached). screenshot from 2016-08-22 10 39 20

Happy to send the input files if necessary via email.

Jon

liamrevell commented 8 years ago

This might be as simple as resizing the plotting device or the text of the plot labels, as I know there can be issues when the tree & labels don't fit in the plotting device as intended. Yes - please feel free to send me the input files and your script and I will look into it.

rwness commented 7 years ago

I am getting the same error message. The 'direct' shape works but with phylogram the plot is only partially drawn and no connecting lines are drawn. I tried, rerooting, removing branch lengths and shortening the labels to single letters.

Did you work out a general solution to this problem?

require(phytools)
tree <-read.tree('nexus23.NoEuro.nwk')
plotTree(tree)
latlong <-read.table("LatLong.invented.txt", header = T)
#convert column 1 to rownames and remove column 1
rownames(latlong) <- latlong$Strain
latlong <- latlong[,2:3]
#This works:
phylo.to.map(tree, latlong,type="direct",ylim=c(38.32,49.12), xlim=c(-141.7, -60.27))
# This does not:
phylo.to.map(tree, latlong,type="phylogram",rotate=T,ylim=c(38.32,49.12), xlim=c(-141.7, -60.27))

objective: 0 objective: 0 objective: 0 objective: 0 objective: 0 objective: 0 objective: 0 objective: 0 Error in xy.coords(x, y) : 'x' and 'y' lengths differ

oddmap

alexweisberg commented 6 years ago

I get this same error when plotting a cophylo plot. The same code works for some trees, however others give this error when I attempt to plot them. obj<-cophylo(multi2di(tree1),multi2di(tree2), rotate.multi=FALSE) pdf(paste0("Figure_", treefilename ,".pdf"),width=18,height=10) plot(obj) dev.off() Rotating nodes to optimize matching... Done. Error in xy.coords(x, y) : 'x' and 'y' lengths differ Calls: plottree ... makelinks -> lines -> lines.default -> plot.xy -> xy.coords Execution halted The pdf file contains a partial cophylo plot without labels or lines.

EDIT: This happens when I have a cophylo plot with duplicate taxa in one of the trees (the tip labels are modified from strain_locus to strain once loaded with ape, so there are identical tip labels). When I drop the duplicates the plot is correct. I guess I could make the labels unique and manually create the association matrix to include both.

liamrevell commented 6 years ago

My suspicion is this has to do with supplying the assoc matrix as a data frame, or, in the case of phylo.to.map, the geographic coordinates in a data frame instead of a matrix. Could this be the case?

jhill1 commented 5 years ago

It is in my case. Had a look at the code: all_otulocs = matrix(0, nrow = length(all_otus), ncol=2) all_otulocs = data.frame(all_otulocs)

So, yep, passing a data.frame not a matrix. Thanks.

biosapo666 commented 5 years ago

Hi Liam i obtain this

Error in coords[cw$tip.label, 2:1] : subscript out of bounds

k-sanchez commented 5 years ago

Hi Liam, I'm getting this error every time I want to plot my tree on a map:

Error in aggregate.data.frame(as.data.frame(x), ...) : 
  arguments must have same length

Note: I load my coordinate file as read.csv; both the number of rows in the coordinate file and the number of terminals in the tree are the same

Thanks!

architasharma23 commented 9 months ago

I was getting this error too Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length

How to solve it - convert your dataframe/csv into a matrix map <- read.csv("Coordinates.csv", header = T, row.names = 1) matrix = as.matrix(map)