r - 将 geom_text 与 geom_jitter 点对齐

标签 r ggplot2

如何在 R ggplot2 的下图中将文本标签与抖动点对齐(沿 x 轴维度) ?

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

enter image description here

最佳答案

简单的解决方案是指定 position_jitter在两者 geom_textgeom_jitterseed .

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

enter image description here

关于r - 将 geom_text 与 geom_jitter 点对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52317280/

相关文章:

r - 将一些分组列添加到 R 中的嵌套数据框

r - 单个 block 内可变的绘图高度

r - grid.arrange from gridExtras exiting with "only ' grobs' allowed in 'gList' "after update

r - 在ggplot2中使符号加粗

r - 在 R plot_ly 中添加 boxplot 显着性指标线和星号

r - 使用 'bife' 包的固定效应 logit 模型的拟合优度

r - 训练、测试、验证和集成数据、混合数据和测试数据之间有什么区别?

r - 如何在 R studio 的概率图中添加一个显示条件变量分布的图层?

r - 在一行/网格中绘制不是使用 ggplot 创建的多个图

r - R中的指数曲线拟合