Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.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
R 错误:应使用'aes()或'aes_u()创建映射`_R - Fatal编程技术网

R 错误:应使用'aes()或'aes_u()创建映射`

R 错误:应使用'aes()或'aes_u()创建映射`,r,R,我发现了错误 错误:应使用aes()或aes_389;()创建映射 2个问题,您不需要数据参数,因为它已经通过管道输入。正如@rpolicastro所说,只有“身份”应该用引号括起来: df %>% group_by(state_name) %>% summarise(TotalPopulation = mean(population_total)) %>% ggplot(data=df, aes(x= state_name, y=TotalPopulation)) +

我发现了错误

错误:应使用
aes()或
aes_389;()创建映射


2个问题,您不需要
数据
参数,因为它已经通过管道输入。正如@rpolicastro所说,只有“身份”应该用引号括起来:

df %>%
 group_by(state_name) %>%
 summarise(TotalPopulation = mean(population_total)) %>%
 ggplot(data=df, aes(x= state_name, y=TotalPopulation)) +
 geom_bar("stat=identity") 

让我们重新创建mtcars的问题

df %>%
 group_by(state_name) %>%
 summarise(TotalPopulation = mean(population_total)) %>%
 ggplot(aes(x= state_name, y=TotalPopulation)) +
 geom_bar(stat="identity") 
有两点需要解决:

  • 您使用管道传递数据,因此应删除
    data=mtcars

  • 报价应该是
    geom\u bar(stat=“identity”)
    而不是
    geom\u bar(“stat=identity”)

下面的代码生成一个绘图

mtcars %>%
  group_by(cyl) %>%
  summarise(TotalMpg = mean(mpg)) %>%
  ggplot(data=mtcars, aes(x= cyl, y=TotalMpg)) +
  geom_bar("stat=identity") 
Error: Mapping should be created with `aes() or `aes_()`

geom_bar中只有“identity”应该在引号中。
mtcars %>%
    group_by(cyl) %>%
    summarise(TotalMpg = mean(mpg)) %>%
    ggplot(aes(x= cyl, y=TotalMpg)) +
    geom_bar(stat="identity")