Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在'geom_bar()中找不到对象`_R_Ggplot2 - Fatal编程技术网

在'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')
吗?是的,这就行了!非常感谢。