介绍
ggrepel包中有两个函数:geom_text_repel()和geom_label_repel()。它们是对geom_text()的扩展,实现了对文本标注的优化。
实例
library(ggplot2)
library(ggrepel)
#使用数据集mtcars演示
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="red")+geom_text(aes(wt, mpg, label=rownames(mtcars)))+theme_classic(base_size = 16)
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="red")+
geom_text_repel(aes(wt, mpg, label=rownames(mtcars)))+
theme_classic(base_size = 16)
ggplot(mtcars)+ geom_point(aes(wt, mpg), color="red")+
geom_label_repel(aes(wt, mpg, label=rownames(mtcars)))+
theme_classic(base_size = 16)