简体   繁体   中英

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 ?

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 .

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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