我是相对较新的用户,在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库。
谢谢!
这是由于使用了错误版本的ggplot2包。根据https://github.com/tidyverse/ggplot2/releases的说法,谷歌搜索显示最新发布的ggplot2 2.2.1是在2016年。
虽然“躲闪2”的位置直到2017年7月才被引入.https://github.com/tidyverse/ggplot2/commits/7d0549a03e5ea08c27c768e88d5717f18cb4a5ce/R/position-dodge2.r
手动安装dev版本包应该可以解决问题。
devtools::install_github("tidyverse/ggplot2")
祝好运。