how to colour tiplabels for ggnetworkx

304 views
Skip to first unread message

Samantha Yap

unread,
Jul 29, 2020, 6:14:30 AM7/29/20
to ggtree

Hi there, 


I am having trouble coloring tiplabels for a splitstree network. Can you help?


my example uses data from phangorn. My script below allows coloring of the network but only if the label is changed (see attached picture). How do I use the original labels that are coloured in the network: 

 [1] "No305"   "No1114S" "No306"   "No304"   "No0913S" "No1202S" "No0910S" "No0906S" "No1206S"

[10] "No0908S" "No1208S" "No0912S" "No1103S" "No1007S" "No0909S"


Help would be greatly appreciated. I tried contacting Klaus Schliep who wrote the scripts for ggnetworkx, but have not heard back from him yet.


cheers,

Sam Yap

####################################################################


library(ggplot2)

library(ggtree)

library(phangorn)

library(ape)

 

#scripts from ggnetworx

source("C:/Users/yaps/Downloads/ggnetworx/R/ggnetworx.R")

 

fdir <- system.file("extdata/trees", package = "phangorn")

 

Nnet <- read.nexus.networx(file.path(fdir,"woodmouse.nxs"))

 

df <- data.frame(s=Nnet$translate$label, reg=c(rep("wood",3),rep("mouse",3),rep("wood",3),rep("mouse",3),rep("wood",3)))

 

Nnet$translate$label <- df$reg

 

###script here generates the network with color but label is not right

ggplot(Nnet, aes(x, y))  + geom_splitnet() + theme_tree()+

  geom_tiplab2(size=1.5) +

  scale_color_manual(values=rainbow(2)) +

  geom_tiplab2(aes(label=label, color=label))+

theme(legend.position="none")

 


network with colored labels.png

Samantha Yap

unread,
Jul 29, 2020, 6:39:34 AM7/29/20
to ggtree
actually this was used.

ggplot(Nnet, aes(x, y))  + geom_splitnet() + theme_tree()+

  scale_color_manual(values=rainbow(2)) +

  geom_tiplab2(aes(label=label, color=label))+

theme(legend.position="none")


Yonghe Xia

unread,
Jul 29, 2020, 8:47:29 AM7/29/20
to ggtree
Why just not rename the tip labels? When  original labels are renamed, they will cease to exist in the tree.

Code it like this.

#remotes::install_github("KlausVigo/c")
library(ape)
library(ggtree)
library(phangorn)
library(ggnetworx)

fdir <- system.file("extdata/trees", package = "phangorn")
Nnet <- read.nexus.networx(file.path(fdir,"woodmouse.nxs"))

ggplot(Nnet, aes(x, y))  + geom_splitnet() + theme_tree()+   
    scale_color_manual(values=rainbow(15)) +   
    geom_tiplab2(aes(label=label, color=label))+
    theme(legend.position="none")

Samantha Yap

unread,
May 23, 2021, 9:35:47 PM5/23/21
to ggtree
Hi there,
I have been using R to plot splitstree nexus outputs. However a mysterious error keeps appearing and I want to know why. Nexus file attached, and script is below with error highlighted in yellow. Does anyone have a solution? because it works just fine with plot(Nnet, "2D).. but I prefer to stick with ggsplitnet if possible. 

Nnet <- read.nexus.networx("C:/Users/yaps/Desktop/rrspecies/PersPauc/PersPauc_SPLITSTREE_test.nex")

ggsplitnet(Nnet)+
  geom_tiplab2()

Error in label[ind] <- model$translate$label : 
    NAs are not allowed in subscripted assignments 

cheers,
Sam

--
1. G Yu*. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. https://doi.org/10.1002/cpbi.96
2. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2020, 37(2):599-603. http://dx.doi.org/10.1093/molbev/msz240
3. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
4. G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. https://doi.org/10.1111/2041-210X.12628
5. Book: https://yulab-smu.github.io/treedata-book/
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/3b1ee49e-6fd5-486f-8a02-825706523c42o%40googlegroups.com.
PersPauc_SPLITSTREE_test.nex
Reply all
Reply to author
Forward
0 new messages