衣带渐宽终不悔分享 http://blog.sciencenet.cn/u/tuqiang2014 在康河的柔波里,做一条水草, 向青草更青处漫溯。

博文

ggtree绘制进化树

已有 9147 次阅读 2018-12-4 14:12 |系统分类:科研笔记

setwd("C:\\Users\\Administrator\\Desktop\\tree")
library("ggtree")
library("ggplot2")
tree <- read.tree("species.tree")
ggtree(tree,layout = "circular")

ggtree(tree, layout="fan", ladderize = FALSE, branch.length = "none")+
  geom_tiplab2(size=3)+ 
  theme(legend.position = "right")

ggtree(tree) + geom_text(aes(label=node), hjust=-.3) + geom_tiplab(size=3)

MRCA(tree, tip=c("Pelobacter_carbinolicus", "uncultured_nitrogen-fixing_bacterium"))
ggtree(tree) + 
  geom_cladelabel(node=40, label="Some random clade", color="red")

ggtree(tree) + 
  geom_tiplab() + 
  geom_cladelabel(node=5, label="Some random clade", 
                  color="red2", offset=-.3, align=TRUE) + 
  geom_cladelabel(node=30, label="A different clade", 
                  color="blue", offset=-.3, align=TRUE) + 
  theme_tree2() + 
#  xlim(0, 1) + 
  theme_tree()

ggtree(tree) + 
  geom_tiplab() + 
  geom_hilight(node=38, fill="gold") + 
  geom_hilight(node=17, fill="purple")

ggtree(tree) + 
  geom_tiplab() + 
  geom_taxalink("Pelobacter_carbinolicus", "uncultured_nitrogen-fixing_bacterium", color="blue3") +
  geom_taxalink("Dysgonomonas_gadei", "uncultured_low_G+C_Gram-positive_bacterium", color="orange2", curvature=-.9)

library("ggstance")
library("vegan")
abun<-read.table("otu_table_group.s.relative.mat.draw",header = T)
colnames(abun)

library("reshape2")

mydata<-melt(abun,id=colnames(abun)[1],measure=colnames(abun)[2:length(colnames(abun))],
             variable.name = "group",value.name = "value")

p <- ggtree(tree)+geom_tiplab(size=3) #+geom_text(aes(label=node), hjust=-.3,size=3) + xlim(0,2) 

p2 <- facet_plot(p, panel="Stacked Barplot", data=mydata, geom = geom_barh,offset = .15,scales="free",
                 mapping = aes(x = decostand(value ,"log"), fill = as.factor(group)), 
                 stat='identity' )+theme_tree2(legend.position="right") #+ theme(legend.position="right") #+theme(legend.position=c(.1, .8))#
p2

p <- ggtree(tree,layout = "fan",ladderize = TRUE)+geom_tiplab2(size=5, align = TRUE, offset = 0.5)
otu_table = read.delim("otu_table_group.s.relative.mat.draw", row.names= 1,  header=T, sep="\t")
otu_table<-log(otu_table+0.0000001)
p3<-gheatmap(p, otu_table, offset = -.010, width=0.5, font.size=3,low = "green",
             high = "red", color = "white", colnames_level=c("S","R","SN","H","K","KN","HN"), 
             hjust = 0)#, colnames_angle=-45, hjust=-.1)
p3

p <- ggtree(tree)+geom_tiplab(size=5, align = TRUE)
p
otu_table = read.delim("otu_table_group.s.relative.mat.draw", row.names= 1,  header=T, sep="\t")
otu_table<-log(otu_table+0.0000001)
p3<-gheatmap(p, otu_table, offset = 0.6, width=0.5, font.size=3,low = "green",
             high = "red", color = "white", colnames_level=c("S","R","SN","H","K","KN","HN"), 
             hjust = 0)#, colnames_angle=-45, hjust=-.1)
p3

Visualizing and Annotating Phylogenetic Trees with R+ggtree
facet_plot: a general solution to associate data with phylogenetic tree



https://blog.sciencenet.cn/blog-1835014-1149804.html

上一篇:三元相图理解以及R实现
下一篇:R语言实现桑基图绘制
收藏 IP: 123.151.22.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (1 个评论)

数据加载中...
扫一扫,分享此博文

全部作者的精选博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-11-24 09:20

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部