【问题标题】:Error message in R using ggplot library: Found object is not a position使用 ggplot 库的 R 中的错​​误消息:找到的对象不是位置
【发布时间】:2018-02-26 16:54:38
【问题描述】:

我是相对较新的用户,在 Rstudio 中使用 R 进行数据可视化。

我想绘制一个从 gss_sm 数据帧传输的频率表:

rel_by_region <- gss_sm %>%
group_by(bigregion, religion) %>%
summarize(N = n()) %>%
mutate(freq = N / sum(N),
       pct = round((freq*100), 0))`


p <- ggplot(rel_by_region, aes(x = bigregion, y = pct, fill = religion))
p + geom_col(position = "dodge2") +
  labs(x = "Region",y = "Percent", fill = "Religion") +
  theme(legend.position = "top")`

显示以下错误消息:

找到的对象不是位置

有人知道我在这里错过了什么吗? ggplot 库已安装。

谢谢!

【问题讨论】:

  • 您的 position 参数中有错字。它是“dodge”而不是“dodge2”
  • 谢谢!我正在使用 Kieran Healy 在他的数据可视化手稿中描述的 ggplot 扩展,他使用了 dodge2,
  • 解决方案是:“dodge2”参数还不是ggplot2的发布版本的一部分,它在ggplot2的开发版本中,使用dodge2将子类别并排放置在组内.要安装它,您可以执行 devtools::install_github("tidyverse/ggplot2")

标签: r ggplot2


【解决方案1】:

这是由于使用了错误的 ggplot2 包版本。 google 搜索显示,根据https://github.com/tidyverse/ggplot2/releases,最新发布的 ggplot2 2.2.1 是在 2016 年。

虽然“dodge2”位置直到 2017 年 7 月才引入。 https://github.com/tidyverse/ggplot2/commits/7d0549a03e5ea08c27c768e88d5717f18cb4a5ce/R/position-dodge2.r

手动安装开发版包应该可以解决问题。

devtools::install_github("tidyverse/ggplot2")

祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-28
    • 1970-01-01
    • 1970-01-01
    • 2011-10-24
    • 1970-01-01
    • 2021-05-05
    相关资源
    最近更新 更多