我想在可能的情况下将标签精确地画在上面(没有重叠),但是ggrepel似乎坚持略高于或低于标绘。例如。
require(ggplot); require(ggrepel)
ggplot(iris[1:10,], aes(Sepal.Length, Sepal.Width)) +
geom_point(pch=1, size=8) +
geom_text_repel(aes(label=Species), segment.color=NA,
point.padding=unit(0, "lines"))

当然,您可以减少force参数,但是当标签重叠时,标签就不会互相排斥。
发布于 2016-10-09 18:28:01
据我所见,您可以通过给point.padding与geom_point(size)相同的值来避免重叠。你可以通过给nudge_y一个很小的加值来定义上面的位置。
library(dplyr)
## an example data (delete duplicated data)
iris2 <- iris %>% distinct(Sepal.Length, Sepal.Width, .keep_all = T)
g <- ggplot(iris2[1:20,], aes(Sepal.Length, Sepal.Width)) + geom_point(pch=1, size=8)
g + geom_text_repel(aes(label=Species), segment.color=NA,
point.padding = unit(8, "points"), nudge_y = 1.0E-6)编辑的
我猜box.padding = unit(-0.5, "lines")给出了点位置的标签(但它可能基于大写字母)。
iris2$Species <- as.character(iris2$Species)
iris2[7,5] <- "ABCDEFG"
g2 <- ggplot(iris2[1:20,], aes(Sepal.Length, Sepal.Width)) + geom_point(pch = 1, size = 8)
g2 + geom_text_repel(aes(label=Species), segment.color=NA, box.padding = unit(-0.5, "lines"))

发布于 2016-10-09 12:26:45
也许你可以改变nudge_y和nudge_x来调整你想要改变每个点的label.If,也许你可以设置一个新的数据框架来支撑标签的坐标。
https://stackoverflow.com/questions/39943123
复制相似问题