当前位置:网站首页>A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png
A code takes you to draw multi format sangjimei pictures such as interactive +pdf+png
2022-07-25 03:20:00 【Liu Yongxin Adam】
Write it at the front
Sangjitu is very nice , It is used to observe the subordinate relationship between different categories , And draw a beautiful structure diagram , Of course, it can be used in many places . Here we use microbiome data phyloseq object , Quickly and easily build a sanggi map for you . So if you have phyloseq Try it directly . The test data in this paper comes from ggClusterNet, Everyone from github Download and use .
actual combat
Import requires R package
library(ggClusterNet)
library(tidyverse)
library(phyloseq)
library(tidyverse)
library(viridis)
library(patchwork)
library(networkD3)
data(ps)We combined microbiological data at genus level , Then take the top 50 genera with the highest abundance , Then remove Unassigned”) %>% vegan_tax() %>% Of microbes . Note that these functions exist in ggClusterNet in , Pay attention to download and installation .
tax = ps %>%
ggClusterNet::tax_glom_wt(ranks = 6) %>%
filter_OTU_ps(50) %>%
subset_taxa(Genus != "Unassigned") %>%
vegan_tax() %>%
as.data.frame()
head(tax)Build connections , A source —- One goal . Mark the labels of different classification levels .
id2 = c("k","p","c","o","f","g")
dat = NULL
for (i in 1:5) {
dat <- tax[,c(i,i+1)] %>% distinct(.keep_all = TRUE)
colnames(dat) = c("source","target")
dat$source = paste(id2[i],dat$source,sep = "_")
dat$target = paste(id2[i+1],dat$target,sep = "_")
if (i == 1) {
dat2 = dat
}
dat2 = rbind(dat2,dat)
}
dim(dat2)
# dat2 = dat2 %>% distinct(.keep_all = TRUE)
head(dat2)Structure abundance table , Here we are only right KO1 This single sample is enriched :
otu = ps %>%
ggClusterNet::tax_glom_wt(ranks = 6) %>%
scale_micro() %>%
filter_OTU_ps(50) %>%
subset_taxa(Genus != "Unassigned") %>%
vegan_otu() %>%
t() %>%
as.data.frame()
head(otu)
otutax = cbind(otu,tax)
id = rank.names(ps)[1:6]
dat = NULL
for (i in 1:6) {
dat <- otutax %>%
group_by(!!sym(id[i])) %>%
summarise(sum(KO1))
colnames(dat) = c("target","value")
dat$target = paste(id2[i],dat$target,sep = "_")
if (i == 1) {
dat3 = dat
}
dat3 = rbind(dat3,dat)
}
dat4 <- dat2 %>% left_join(dat3)
sankey = dat4Construct nodes and connection tables , preservation html file ,pdf and png file .
nodes <- data.frame(name = unique(c(as.character(sankey$source),as.character(sankey$target))),stringsAsFactors = FALSE)
nodes$ID <- 0:(nrow(nodes)-1)
sankey <- merge(sankey,nodes,by.x = "source",by.y = "name")
sankey <- merge(sankey,nodes,by.x = "target",by.y = "name")
colnames(sankey) <- c("X","Y","value","source","target")
sankey <- subset(sankey,select = c("source","target","value"))
nodes <- subset(nodes,select = c("name"))
ColourScal='d3.scaleOrdinal() .range(["#E41A1C", "#377EB8", "#4DAF4A", "#984EA3", "#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"])'
sankey$energy_type <- sub(' .*', '', nodes[sankey$source + 1, 'name'])
p <- sankeyNetwork(Links = sankey, Nodes = nodes,
Source = "source",Target = "target",Value = "value",
NodeID = "name",
sinksRight=FALSE,
LinkGroup = 'energy_type',
colourScale= ColourScal,
# nodeWidth=40,
# fontSize=13
# nodePadding=20
)
p
saveNetwork(p,"sankey1.html")
library(webshot)
webshot("sankey.html" , "sankey.png")
webshot("sankey.html" , "sankey.pdf")
Guess you like
iMeta brief introduction Highly quoted articles High color value drawing imageGP Network analysis iNAP
iMeta Web tools Metabolism group MetOrigin Meggie cloud Lactation prediction DeepKla
iMeta review Intestinal flora Plant flora Oral flora Protein structure prediction
10000+: Flora analysis Babies and dogs Rhapsody of syphilis carry DNA Hair Nature
Series of tutorials : Introduction to microbiome Biostar Microbiome Macro genome
Expertise : Academic charts High score article Shengxin Scripture An indispensable person
Article to read : Macro genome Parasite benefits Evolutionary tree Necessary skills : put questions to Search for Endnote
Amplification analysis : Chart interpretation Analysis process Statistical mapping
16S Function prediction PICRUSt FAPROTAX Bugbase Tax4Fun
Biological science : Intestinal bacteria Life on the human body Great leap forward in life Cell warfare The mystery of human body
Written in the back
To encourage readers to communicate and quickly solve scientific research difficulties , We established “ Macro genome ” Discussion groups , There are already domestic and foreign 6000+ Researchers join . Please add editor in chief wechat meta-genomics Bring you into the group , Be sure to remark “ full name - Company - Research direction - The title / grade ”. Please indicate your identity for the senior title , There are also microorganisms at home and abroad PI Cooperation and exchange of group supply . Ask for help with technical problems , First read 《 How to ask questions gracefully 》 Learn how to solve problems , Unresolved intra group discussions , Don't talk about problems in private , Help colleagues .
Click to read the original text , Jump to the latest article catalog to read
边栏推荐
- Matplotlib tutorial (I) [getting to know Matplotlib first]
- JS foundation -- regular expression
- C language function operation
- C language_ Structure introduction
- Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
- A queue of two stacks
- TypeScript
- Question D: pruning shrubs
- Tensorflow's study notes (I)
- Leetcode programming practice -- Tencent selected 50 questions (I)
猜你喜欢
![[stm32f103rct6] can communication](/img/24/71509bd0d74d43ce4a79b8126478ff.jpg)
[stm32f103rct6] can communication

JS written test questions -- random numbers, array de duplication

Calculation method of confusion matrix

Dc-1-practice

How to use two queues to simulate the implementation of a stack

Riotboard development board series notes (VII) -- the use of framebuffer

Electronic bidding procurement mall system: optimize traditional procurement business and speed up enterprise digital upgrading
![[stm32f130rct6] idea and code of ultrasonic ranging module](/img/a6/1bae9d5d8628f00acf4738008a0a01.png)
[stm32f130rct6] idea and code of ultrasonic ranging module

Banana pie bpi-m5 toss record (3) -- compile BSP

Riotboard development board series notes (6) -- buildreoot building system image
随机推荐
NVM installation and use
Wechat H5 record
Innobackupex parameter description
Idea configuration
Lombok detailed introduction
The dolphin scheduler calls the shell script and passes multiple parameters
C language_ Defining structures and using variables
From input URL to page presentation
Leetcode programming practice -- Tencent selected 50 questions (I)
Openlayers ol ext: Transform object, rotate, stretch, zoom in
Solve the error: could not find 'xxxtest‘
Merge sort / quick sort
C language function operation
JS written test -- regular expression
B. Almost Ternary Matrix
Recursive and non recursive methods are used to realize the first order, middle order and second order traversal of binary tree respectively
Function of each layer of data warehouse
Riotboard development board series notes (V) -- porting u-boot
Take a database statement note: when the field is empty, assign the default value to the result
Use reflection to convert RDD to dataframe