【问题标题】:Error when trying to override aesthetics with geom_rect() [closed]尝试使用 geom_rect() 覆盖美学时出错 [关闭]
【发布时间】:2015-10-08 14:14:29
【问题描述】:

我不想在 ggplot 函数中定义美学,而是在以下几何图形中定义,因为我打算使用一些。

library(ggplot2)

df <- data.frame(
  x = sample(10, 20, replace = TRUE),
  y = sample(10, 20, replace = TRUE)
)

这行得通:

ggplot(df, aes(xmin = x, xmax = x + 1, ymin = y, ymax = y + 2)) +
geom_rect()

这没有,我得到“错误:不知道如何将 o 添加到绘图中”

ggplot(df) +
geom_rect(aes(xmin = x, xmax = x + 1, ymin = y, ymax = y + 2))

但如果我更改 geom_point 的 geom,它会再次起作用:

ggplot(df) +
geom_point(aes(x = x, y = y))

感谢您的帮助!

编辑:似乎对某些人有用! 当我启动一个新的 R 会话并且只加载 ggplot2 时,它也适用于我。 我会继续寻找造成这种行为的包

【问题讨论】:

  • 两者都适合我。
  • 我也无法重现错误。

标签: r graphics plot ggplot2


【解决方案1】:

找到问题了!

“ggbio”包 (ggbio_1.16.1) 负责此行为并影响 ggplot2 函数。

不加载“ggbio”为我解决了这个问题。

【讨论】:

  • 我的情节需要使用 ggbio,所以我不想禁用它。在情节中明确说明ggplot2::geom_rect() 解决了这个问题。
猜你喜欢
  • 2022-07-08
  • 2021-03-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-31
  • 1970-01-01
相关资源
最近更新 更多