【问题标题】:Subdividing jitter points in ggplot在ggplot中细分抖动点
【发布时间】:2020-10-30 10:05:49
【问题描述】:

我很难让geom_jitter 用第三个变量(相位)分隔我的数据点。

我希望这个 2x2 图表中的每个条形都有自己的一组针对每个相位条件的抖动数据点。

现在点在两个阶段栏之间分组(抱歉无法上传图片——我的 10 个帖子还没有)。

我知道我在geom_jitter aes 中遗漏了一些东西,但不确定它是什么——fill=phase 没有做到这一点。

ggplot(datalong, aes(grp, score)) +
  geom_bar(stat = "summary", fun.y = "mean", aes(fill=phase), position = "dodge", alpha = .5) +
  geom_jitter(inherit.aes = FALSE, aes(grp, score, fill=phase), position = position_jitter(0.2)) 

【问题讨论】:

标签: r ggplot2 geom-bar


【解决方案1】:

点的默认形状不采用填充美学

比较

library(ggplot2)
ggplot(mtcars, aes(mpg, disp, fill = gear)) +
  geom_jitter()

ggplot(mtcars, aes(mpg, disp, color = gear)) +
  geom_jitter()

ggplot(mtcars, aes(mpg, disp, fill = gear)) +
  geom_jitter(shape = 21)

reprex package (v0.3.0) 于 2020-07-09 创建

【讨论】:

    【解决方案2】:

    使用以下方法找到了解决方案: geom_point(position=position_jitterdodge())

    这似乎在抖动和闪避以分开点。

    【讨论】:

      猜你喜欢
      • 2016-06-28
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 2021-08-04
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      相关资源
      最近更新 更多