查看原文
其他

Growing a ggtree - part 2, adding tip shapes

2017-07-14 Anthony biobabble

Adding tip labels

In addition to adding a heatmap I found that adding coloured shapes to tips was a useful feature

  • First off read and plot the tree as before

     tree <- read.tree("/path/to/newick/tree")  p <- ggtree(tree, right = TRUE)  plot(p)
  • Next read in an additional tsv file with taxa names in the first column and meta data to plots as shapes in additional columns

     # read in tiplabel metadata  tip_metadata <- read.table("meta_data.txt", sep="\t", header=TRUE,check.names=FALSE, stringsAsFactor=F)

    The format for this is as follows:

taxaage_groupcountry_of_residence
sample1adult femaleScotland
sample2adult maleWales
sample3child femaleEngland
sample4child maleEngland
  • This data can then be plotted as tip labels where the colours are either determined randomly

     p <- p %<+% tip_metadata + geom_tippoint(aes(color=age_group), size=3)  plot(p)

  • Or if you want to enter them manually use the scale_color_manual functionality where colours are assigned to the column values based on alphabetical order

     p <- p %<+% tip_metadata + geom_tippoint(aes(color=age_group), size=3) + scale_color_manual(values=c("red", "blue","green","grey"))  plot(p)

  • The shapes can be altered based on another columns

     p <- p %<+% tip_metadata + geom_tippoint(aes(color=age_group, shape=country_of_residence), size=3) + scale_color_manual(values=c("red", "blue","green","grey"))

  • To specify the shapes manually use the + scale_shape_manual function

     p <- p %<+% tip_metadata + geom_tippoint(aes(color=age_group, shape=country_of_residence), size=3) + scale_color_manual(values=c("red", "blue","green","grey")) + scale_shape_manual(values=c(1,2,3))

The shape numbers can be found here



您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存