美文网首页
ggrepel解决标签之间重叠问题

ggrepel解决标签之间重叠问题

作者: 生信编程日常 | 来源:发表于2020-12-13 16:54 被阅读0次

有时候画图需要给样本添加标签,当样本比较多,在图形中添加标签容易出现标签遮盖的问题,这个时候可以用ggrepel包的geom_text_repel()解决样本标签重叠问题。
当用geom_text()添加标签时会出现重叠现象:

ggplot(mtcars)+ geom_point(aes(wt, mpg), color="blue")+ 
  geom_text(aes(wt, mpg, label=rownames(mtcars)))+ 
  theme_classic(base_size = 16)

用geom_text_repel()代替geom_text()时则不会重叠:

library(ggrepel)
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="blue")+ 
  geom_text_repel(aes(wt, mpg, label=rownames(mtcars)))+
  theme_classic(base_size = 16)

在用seurat分析单细胞数据时也常出现标签覆盖问题,
可以通过设置repel = TRUE来解决。

DimPlot(brain.integrated, reduction = "umap", group.by = "orig.ident", label = TRUE) + NoLegend()
DimPlot(brain.integrated, reduction = "umap", group.by = "orig.ident", label = TRUE, repel = TRUE) + NoLegend() 

相关文章

网友评论

      本文标题:ggrepel解决标签之间重叠问题

      本文链接:https://www.haomeiwen.com/subject/kllpgktx.html