【问题标题】:Adding space between geom_pointrange()在 geom_pointrange() 之间添加空间
【发布时间】:2022-11-11 07:02:42
【问题描述】:

我正在复制一个人物,我非常接近回家。但我只是不知道如何在两个 geom_pointrange(s)() 之间添加空间。

谁能给我一个提示? 谢谢。

【问题讨论】:

  • 没有看到你的 data.frame df 的结构有点棘手。也许您可以考虑将dfdfcontrol 与第三个变量(例如type)组合成一个数据帧(例如使用rbind),其中df$type <- "exp"dfcontrol$type <- "control"。然后在你的 ggplot 中使用 group = type aesposition_dodge()

标签: r ggplot2 aesthetics geom


【解决方案1】:

position_nudge 成功了。使用一些虚拟数据:

data.frame(expcondition = c('A', 'B'),
           coefs = 6:7) %>%
ggplot(aes(expcondition, coefs)) + 
geom_pointrange(aes(ymin = coefs * .9, ymax = coefs * 1.2)) +
geom_pointrange(aes(ymin = coefs * .8, ymax = coefs * 1.1), col = 'grey',
                ## add some horizontal shift:
                position = position_nudge(x = .1)
                )

旁白:作为用户克福隆建议、合并和pivoting your data into long format 通常有助于处理您的数据,而不仅仅是ggplotting。

【讨论】:

  • 你是个传奇,先生。太感谢了。
猜你喜欢
  • 2013-07-12
  • 2018-06-15
  • 2015-10-15
  • 1970-01-01
  • 2017-06-06
  • 2017-06-13
  • 1970-01-01
  • 1970-01-01
  • 2019-04-29
相关资源
最近更新 更多