将geom_text与geom_jitter点对齐 [英] Aligning geom_text to geom_jitter points
本文介绍了将geom_text与geom_jitter点对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在R ggplot2
的以下图中将文本标签与抖动点对齐(沿x轴尺寸)?
How can I align (along the x axis dimension) the text labels with the jittered points in the following plot in R ggplot2
?
library(dplyr)
library(ggplot2)
mtcars %>%
ggplot(aes(am, wt, group = am, label = wt)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter() +
geom_text()
推荐答案
简单的解决方案是在 geom_text
和 geom_jitter
中指定 position_jitter
具有相同的 seed
.
Easy solution would be to specify position_jitter
in both geom_text
and geom_jitter
with the same seed
.
library(ggplot2)
ggplot(mtcars, aes(am, wt, group = am, label = wt)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(position = position_jitter(seed = 1)) +
geom_text(position = position_jitter(seed = 1))
这篇关于将geom_text与geom_jitter点对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文