简体   繁体   English

将geom_text与geom_jitter点对齐

[英]Aligning geom_text to geom_jitter points

How can I align (along the x axis dimension) the text labels with the jittered points in the following plot in R ggplot2 ? 如何将(沿x轴维度)文本标签与R ggplot2下图中的抖动点ggplot2

library(dplyr)
library(ggplot2)
mtcars %>% 
    ggplot(aes(am, wt, group = am, label = wt)) +
    geom_boxplot(outlier.shape = NA) +
    geom_jitter() +
    geom_text()

在此输入图像描述

Easy solution would be to specify position_jitter in both geom_text and geom_jitter with the same seed . 简单的解决方案是使用相同的seedgeom_textgeom_jitter指定position_jitter

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))

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM