Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何调整Biomarker可视化过程中,显示label的数量 #94

Open
liuninghua521 opened this issue Jun 7, 2023 · 3 comments
Open

Comments

@liuninghua521
Copy link

liuninghua521 commented Jun 7, 2023

老师好,我想知道在这一步该怎么调整label的数量,调整成显示丰度前10的门,其余可以合并为other之类的显示格式

display the high light of phylum clade.

p2 <- p1 +
geom_hilight(
data = td_filter(nodeClass == "Phylum"),
mapping = aes(node = node, fill = label)
)

我在可视化自己的数据,这一步显示出来的门太多了

@liuninghua521 liuninghua521 reopened this Jun 7, 2023
@liuninghua521 liuninghua521 changed the title 如何调整Biomarker可视化中的因子顺序。 如何调整Biomarker可视化过程中,显示label的数量 Jun 7, 2023
@liuninghua521 liuninghua521 reopened this Jun 7, 2023
@liuninghua521
Copy link
Author

补充
老师,我还想知道该怎么调整样本和分组的因子顺序,就是将sample和time按自己想要的顺序排列

display the relative abundance of features(OTU)

p3 <- p2 +
ggnewscale::new_scale("fill") +
geom_fruit(
data = td_unnest(RareAbundanceBySample),
geom = geom_star,
mapping = aes(
x = fct_reorder(Sample, time, .fun=min),
size = RelRareAbundanceBySample,
fill = time,
subset = RelRareAbundanceBySample > 0
),
starshape = 13,
starstroke = 0.25,
offset = 0.04,
pwidth = 0.8,
grid.params = list(linetype=2)
) +
scale_size_continuous(
name="Relative Abundance (%)",
range = c(.5, 3)
) +
scale_fill_manual(values=c("#1B9E77", "#D95F02"))

我尝试使用
taxa.tree@extraInfo$RareAbundanceBySample <- lapply(taxa.tree@extraInfo$RareAbundanceBySample, function(df) {
df$Sample <- factor(df$Sample, levels = sample_order)
return(df)
})
的方式直接修改,但是没有效果。
麻烦老师了。

@xiangpin
Copy link
Member

我在可视化自己的数据,这一步显示出来的门太多了

可以用mutate先生成一列新的label(调整后的phylum的名字或者其他水平都可以)然后再画,比如

> taxa.tree
'treedata' S4 object'.

...@ phylo:

Phylogenetic tree with 218 tips and 186 internal nodes.

Tip labels:
  OTU_67, OTU_231, OTU_188, OTU_150, OTU_207, OTU_5, ...
Node labels:
  r__root, k__Bacteria, p__Actinobacteria, p__Bacteroidetes, p__Cyanobacteria,
p__Deinococcus-Thermus, ...

Rooted; no branch lengths.

with the following features available:
  'nodeClass', 'nodeDepth', 'RareAbundanceBySample', 'RareAbundanceBytime'.

# The associated data tibble abstraction: 404 × 7
# The 'node', 'label' and 'isTip' are from the phylo tree.
    node label   isTip nodeClass nodeDepth RareAbundanceBySample
   <int> <chr>   <lgl> <chr>         <dbl> <list>
 1     1 OTU_67  TRUE  OTU               8 <tibble [19 × 4]>
 2     2 OTU_231 TRUE  OTU               8 <tibble [19 × 4]>
 3     3 OTU_188 TRUE  OTU               8 <tibble [19 × 4]>
 4     4 OTU_150 TRUE  OTU               8 <tibble [19 × 4]>
 5     5 OTU_207 TRUE  OTU               8 <tibble [19 × 4]>
 6     6 OTU_5   TRUE  OTU               8 <tibble [19 × 4]>
 7     7 OTU_1   TRUE  OTU               8 <tibble [19 × 4]>
 8     8 OTU_2   TRUE  OTU               8 <tibble [19 × 4]>
 9     9 OTU_3   TRUE  OTU               8 <tibble [19 × 4]>
10    10 OTU_4   TRUE  OTU               8 <tibble [19 × 4]>
# ℹ 394 more rows
# ℹ 1 more variable: RareAbundanceBytime <list>
# ℹ Use `print(n = ...)` to see more rows
> taxa.tree %>% dplyr::mutate(new.label=dplyr::if_else(label %in% c("p__Actinobacteria", "p__Bacteroidetes", "p__Cyanobacteria"), "Others", label)) %>% ggtree(layout='cir') + geom_hilight(data=td_filter(nodeClass=='Phylum'), mapping=aes(node = node, fill=new.label)) -> p1
> taxa.tree %>% ggtree(layout='cir') + geom_hilight(data = td_filter(nodeClass=='Phylum'), mapping=aes(node = node, fill=label)) -> p2
> p1 / p2

捕获

|> 我还想知道该怎么调整样本和分组的因子顺序,就是将sample和time按自己想要的顺序排列

可以在geom_fruit图层里先用td_mutate去调整samplefactor

> taxa.tree %>% tidyr::unnest(RareAbundanceBySample) %>% dplyr::pull(Sample) %>% unique() %>% sample() -> s1
# A tbl_df is returned for independent data analysis.
> s1
 [1] "F3D1"   "F3D147" "F3D5"   "F3D145" "F3D143" "F3D150" "F3D148" "F3D146"
 [9] "F3D141" "F3D2"   "F3D142" "F3D0"   "F3D7"   "F3D9"   "F3D8"   "F3D3"
[17] "F3D149" "F3D6"   "F3D144"
> p <- ggtree(taxa.tree, layout = 'cir')
> p + geom_fruit(data = td_mutate(Sample=factor(Sample, levels=s1), .f=td_unnest(RareAbundanceBySample)), geom = geom_tile, mapping = aes(subset=RareAbundance>0, fill=time, x=Sample))

Uploading 捕获.PNG…

如果你觉得有点陌生,td_mutate(Sample = factor(Sample, levels= s1), .f = td_unnest(RareAbundanceBySample))(p$data)看看数据。td_unnest, td_filter, td_mutate这三个函数主要就是传到图层里的data参数,然后用这个函数去整理p$data里的数据。

@liuninghua521
Copy link
Author

谢谢老师!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants