在'geom_bar()中找不到对象`
我想将在'geom_bar()中找不到对象`,r,ggplot2,R,Ggplot2,我想将prop映射到条形图上的y轴,但我一直得到“未找到对象”错误。如何修复代码?谢谢大家! dput(starwars_age) structure(list(`Age Response` = c("> 60", "18-29", "30-44", "45-60" ), n = c(193L, 180L, 207L, 240L), prop = c(0.206196581196581, 0.19230769
prop
映射到条形图上的y轴,但我一直得到“未找到对象”错误。如何修复代码?谢谢大家!
dput(starwars_age)
structure(list(`Age Response` = c("> 60", "18-29", "30-44", "45-60"
), n = c(193L, 180L, 207L, 240L), prop = c(0.206196581196581,
0.192307692307692, 0.221153846153846, 0.256410256410256)), row.names = c(NA,
-4L), class = c("tbl_df", "tbl", "data.frame"))
starwars_age %>%
mutate(`Age Response` = factor(`Age Response`, levels = c("18-29","30-44","45-60","> 60"))) %>%
ggplot(aes(x = `Age Response`))+
geom_bar(aes(y = prop))
Error in layer(data = data, mapping = mapping, stat = stat, geom = GeomBar, : object 'prop' not found
我们可以在
geom\u栏中添加stat='identity'
:
library(dplyr)
library(ggplot2)
starwars_age %>%
mutate(`Age Response` = factor(`Age Response`,
levels = c("18-29","30-44","45-60","> 60"))) %>%
ggplot(aes(x = `Age Response`)) +
geom_bar(aes(y = prop), stat = 'identity')
您想要几何图形条(aes(y=prop),stat='identity')
吗?是的,这就行了!非常感谢。