有时候画图需要给样本添加标签,当样本比较多,在图形中添加标签容易出现标签遮盖的问题,这个时候可以用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()

网友评论