3

可能であれば(オーバーラップなしで)ポイントの上にラベルを正確にプロットしたいのですが、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たときにラベルが互いに反発し合うことはありません。

4

2 に答える 2

5

私が見る限り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-09T18:28:01.400 に答える
0

nudge_y と nudge_x を変更してラベルを調整できるかもしれません。各ポイントを変更したい場合は、新しいデータ フレームを設定して、ラベルの座標を調整できます。

于 2016-10-09T12:26:45.003 に答える