ggplot2对象的动态位置(特别是geom_text)? [英] Dynamic position for ggplot2 objects (especially geom_text)?
问题描述
使用ArcGIS制作地图时,默认情况下软件会自动推送点和多边形标签,以避免使用专有算法进行重叠。他们将此称为
图摘自此博客文章。
When using ArcGIS to make maps, the software by default pushes point and polygon labels around automatically to avoid overlap using a proprietary algorithm. They refer to this as dynamic labeling. ggplot2
has position_jitter
which is excellent for points (since dynamic labeling might create systematic bias), but less good for labels using geom_text
.
Here's an example of some problems with jitter that a dynamic labeling algorithm might solve:
library(ggplot2)
ggplot( mtcars,aes( x=wt, y=mpg, label=rownames(mtcars) ) ) +
geom_point() +
geom_text( position=position_jitter(h=1,w=1) )
Does such a dynamic labeling feature exist already in ggplot2?
If not, what algorithms exist for doing so and is it possible to implement a position_dynamic
in R?
Check out the new package ggrepel. ggrepel provides geoms for ggplot2 to repel overlapping text labels. It works both for geom_text and geom_label.
Figure is taken from this blog post.
这篇关于ggplot2对象的动态位置(特别是geom_text)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!