当前位置:网站首页>How to use R package ggtreeextra to draw evolution tree
How to use R package ggtreeextra to draw evolution tree
2022-06-24 19:14:00 【Yisu cloud】
How do you use it? R package ggtreeExtra Draw evolution tree
This article “ How do you use it? R package ggtreeExtra Draw evolution tree ” Most people don't quite understand the knowledge points of the article , So I made up the following summary for you , Detailed content , The steps are clear , It has certain reference value , I hope you can gain something after reading this article , Let's take a look at this article “ How do you use it? R package ggtreeExtra Draw evolution tree ” Article bar .
introduction
ggplot2 Provided geom_tile Layer can draw heat map ,ggplot2 Of geom_point perhaps ggstar Of geom_star You can draw point layers . In order to extend the ggtree Present relevant data on the outer ring of the phylogenetic tree in the point and layout , Developed ggtreeExtra Package provides a function ,geom_fruit Used to align the graph with the tree , The related charts will be aligned in different positions on the outer panel of the tree . Also developed geom_fruit_list Add multiple layers on the same external panel of the tree . Some functions are based on ggplot2 And support the use of graphical syntax .
Drawing examples
1、 Download and install ggtreeExtra package
if(!requireNamespace("remotes", quietly=TRUE)){ install.packages("remotes")}remotes::install_github("YuLab-SMU/ggtreeExtra")if (!requireNamespace("BiocManager", quietly=TRUE)) install.packages("BiocManager")BiocManager::install("ggtreeExtra")BiocManager::install("ggstar")# download "ggstar","ggplot2","ggtree","treeio","ggnewscale" package install.packages("ggstar")install.packages("ggplot2")install.packages("ggtree")install.packages("treeio")install.packages("ggnewscale")2、 Load dependent package
library(ggtreeExtra) # Set superimposed packages library(ggstar) # Provide Geometry library(ggplot2) # library(ggtree) # Draw evolution tree library(treeio)library(ggnewscale) # Create a new scale, Multiple fill perhaps color
3、 Set up the working directory
setwd("D:/R/ggtreeExtra")4、 Data sources
# Tree view data source path trfile <- system.file("extdata", "tree.nwk", package="ggtreeExtra")# Draw the data source path of point graph and histogram tippoint1 <- system.file("extdata", "tree_tippoint_bar.csv", package="ggtreeExtra")# The first layer outside the tree draws the heat map to the data source path ring1 <- system.file("extdata", "first_ring_discrete.csv", package="ggtreeExtra")# The second layer outside the tree draws the heat map to the data source path ring2 <- system.file("extdata", "second_ring_continuous.csv", package="ggtreeExtra")5、 get data
The tree file is using read . tree Imported . If there are other tree format files , have access to tree io Package to read .
tree <- read.tree(trfile)data = fortify(tree)head(data)

6、 Draw a tree view
# Visual evolutionary tree , The graph here is "fan", It can also be 'rectangular', 'dendrogram', 'slanted', 'ellipse', 'roundrect', 'circular', 'circular', 'inward_circular', 'radial', 'equal_angle', 'daylight' or 'ape'p <- ggtree(tree, layout="fan", open.angle=10, size=0.5)p

7、 Get data set plot
dat1 <- read.csv(tippoint1)knitr::kable(head(dat1))dat2 <- read.csv(ring1)knitr::kable(head(dat2))dat3 <-read.csv(ring2)knitr::kable(head(dat3))head(dat3)
dat1 Datasets are used to plot points and bars

dat2 Datasets are used to plot heat maps

dat3 Datasets are used to plot heat maps

a、 Draw a point layer
p2 <- p + geom_fruit( data=dat1, geom=geom_star, mapping=aes(y=ID, fill=Location, size=Length, starshape=Group), position="identity", starstroke=0.2 ) + scale_size_continuous( range=c(1, 3), # Size range guide=guide_legend( keywidth=0.5, # Box width 0.5 Keyheight=0.5, # Box width 0.5 override.aes=list(starshape=15), order=2 ) ) + scale_fill_manual( values=c("#F8766D", "#C49A00", "#53B400", "#00C094", "#00B6EB", "#A58AFF", "#FB61D7"), guide="none" ) + scale_starshape_manual( values=c(1, 15), guide=guide_legend( keywidth=0.5, keyheight=0.5, order=1 ) )p2
b、 Draw a hot layer
p3 <- p2 + new_scale_fill() + geom_fruit( data=dat2, geom=geom_tile, mapping=aes(y=ID, x=Pos, fill=Type),offset=0.08, # The distance between the outer layers , The default is the... Of the tree x Scope 0.03 times .pwidth=0.25 # The width of the outer layer , The default is the... Of the tree x Scope 0.2 times . ) + scale_fill_manual( values=c("#339933", "#dfac03"),guide=guide_legend(keywidth=0.5,keyheight=0.5, order=3) ) p3
c、 Draw a hot layer
p4 <- p3 + new_scale_fill() + geom_fruit( data=dat3, geom=geom_tile, mapping=aes(y=ID, x=Type2, alpha=Alpha, fill=Type2), pwidth=0.15, axis.params=list( axis="x", # Add the axis text of the layer text.angle=-45, #x Text angle of the axis hjust=0 # Adjust the horizontal position of the text axis ) ) + scale_fill_manual( values=c("#b22222", "#005500", "#0000be", "#9f1f9f"), guide=guide_legend(keywidth=0.5, keyheight=0.5, order=4) ) + scale_alpha_continuous(range=c(0, 0.4), # alpha The scope of the guide=guide_legend(keywidth=0.5, keyheight=0.5, order=5) ) p4
d、 Draw a columnar layer
p5 <- p4 + new_scale_fill() + geom_fruit( data=dat1, geom=geom_bar,mapping=aes(y=ID, x=Abundance, fill=Location), # dat 1 Of Abundance Will be mapped to x pwidth=0.4, stat="identity", orientation="y", # Axis direction axis.params=list( axis="x", # Add the axis text of the layer text.angle=-45, # The text size of the axis hjust=0 # Adjust the horizontal position of the axis text ), grid.params=list() # Add gridlines to the external bar chart ) + scale_fill_manual( values=c("#F8766D", "#C49A00", "#53B400", "#00C094", "#00B6EB", "#A58AFF", "#FB61D7"), guide=guide_legend(keywidth=0.5, keyheight=0.5, order=6) ) + theme(#legend.position=c(0.96, 0.5), # Legend location legend.background=element_rect(fill=NA), # Legend background legend.title=element_text(size=7), # Legend Title Size legend.text=element_text(size=6), # Legend text label size legend.spacing.y = unit(0.02, "cm") # Adjust the y The distance of the axis legend ) p5
That's about “ How do you use it? R package ggtreeExtra Draw evolution tree ” The content of this article , I believe we all have a certain understanding , I hope the content shared by Xiaobian will be helpful to you , If you want to know more about it , Please pay attention to the Yisu cloud industry information channel .
边栏推荐
- starring V6平台开发接出点流程
- The cdc+mysql connector joins the date and time field from the dimension table by +8:00. Could you tell me which one is hosted by Alibaba cloud
- Exponential regression in R
- 为什么 useEvent 不够好
- 论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
- [computer talk club] Lecture 3: how to raise key issues?
- MySQL basic commands
- The verifiable certificate of geoscience remote sensing industry
- Development of NFT dual currency pledge liquidity mining system
- How to deal with the problem that the Flink CDC reads MySQL in full and always reports this error
猜你喜欢

【Leetcode】旋转系列(数组、矩阵、链表、函数、字符串)

Source code analysis of ArrayList

Sr-gnn shift robot gnns: overlapping the limitations of localized graph training data

How to customize cursor position in wechat applet rotation chart

Value passing and reference passing of value types and reference types in CSharp

模块五

Solve the problem that the MapReduce program console does not have log information warn please initialize the log4j system properly

AI时代生物隐私如何保护?马德里自治大学最新《生物特征识别中的隐私增强技术》综述,全面详述生物隐私增强技术

Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling

Volcano成Spark默认batch调度器
随机推荐
The script implements the automated deployment of raid0
subject may not be empty [subject-empty]
MySQL binlog data source configuration document, please share
How to perform power regression in R
微信小程序轮播图怎么自定义光标位置
论文解读(SR-GNN)《Shift-Robust GNNs: Overcoming the Limitations of Localized Graph Training Data》
Starring develops httpjson access point + Database
我用sql形式的会出现cdc读取乱序吗
Interpreting harmonyos application and service ecology
cdc+mysql connector从维表中join的日期时间字段会被+8:00,请问阿里云托管的
okcc呼叫中心数据操作的效率问题
A detailed explanation of the implementation principle of go Distributed Link Tracking
Experience of MDM master data project implementation for manufacturing projects
1: Mosaic of 100W basic geographic information data
网络安全审查办公室对知网启动网络安全审查
AI时代生物隐私如何保护?马德里自治大学最新《生物特征识别中的隐私增强技术》综述,全面详述生物隐私增强技术
香港服务器租用错误可能导致严重后果
Understanding openstack network
Tkde2022: Dialogue recommendation system based on knowledge enhanced sampling
Will the CDC read out of order when I use SQL