nodepie function not using values in data frame

30 views Asked by At

Q: The pie charts produced using nodepie within ggtree is not using the numbers from a specified data frame. [SOLVED see end of post]

I have a large tree, and the code for making the plot is below:

p1<-ggtree(tree, ladderize = TRUE, branch.length = "none", right = TRUE)

I have a matrix that I've modified which has posterior probabilities of five traits for each of four nodes, where each row equals 1 and includes a 'node' column:

nodeTest<-data.frame(A=c(0.0958211092749001,0.0637862609375507,0.463996386876187,0.00165395365974673),B=c(0.390789314936616,0.0528965215595085,0.23601740209132,0.00195511257329542),C=c(0.0531783209956143,0.704308173828317,0.0163010480752175,0.0740274150681192),D=c(0.459159498364088,0.0980025477225612,0.283044455979883,0.00248691661024461),E=c(0.00105175642878233,0.0810064959520626,0.000640706977391879,0.919876602088594))
namesTest<-c("349","350","358","405")
nodeTest<-cbind(nodeTest,namesTest)
colnames(nodeTest)<-c("A","B","C","D","E","node")
nodeTest1<-as.data.frame(nodeTest)

So the data frame looks like this:

                      A                   B                  C                   D                   E     node
349  0.0958211092749001   0.390789314936616 0.0531783209956143   0.459159498364088 0.00105175642878233   349
350  0.0637862609375507  0.0528965215595085  0.704308173828317  0.0980025477225612 0.0810064959520626    350
358   0.463996386876187    0.23601740209132 0.0163010480752175   0.283044455979883 0.000640706977391879  358
405 0.00165395365974673 0.00195511257329542 0.0740274150681192 0.00248691661024461 0.919876602088594     405    

When I do the below code, I get the attached image with four pie charts.

piesTest<-nodepie(nodeTest1,cols = 1:5)
inset(p1,piesTest, width = 0.035,height = 0.035)

enter image description here

The pie charts are at the correct nodes, but the wedges 1) are all equal to each other instead of reflecting what is in nodeTest1 data frame, and 2) the order of those wedges is different, judging from the color orders in each. I am new to using ggtree, and can run other examples with the pie charts matching what is in the data frame, but when I set up my data in the same way, I get different results. Any help is much appreciated, thank you!

EDIT: I have figured it out. When I did cbind with the full data set, it changed everything to a character. I had to set each column as.numeric within the data frame, and then it worked.

0

There are 0 answers