Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when plotting phylo.to.map #6

Open
jhill1 opened this issue Aug 22, 2016 · 8 comments
Open

Error when plotting phylo.to.map #6

jhill1 opened this issue Aug 22, 2016 · 8 comments

Comments

@jhill1
Copy link

jhill1 commented Aug 22, 2016

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
Copy link
Owner

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.

  • Liam

@rwness
Copy link

rwness commented Apr 12, 2017

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
Copy link

alexweisberg commented Apr 13, 2018

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
Copy link
Owner

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
Copy link
Author

jhill1 commented Oct 7, 2018

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
Copy link

Hi Liam
i obtain this

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

@k-sanchez
Copy link

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
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants