stat_count() must not be used with a y aesthetic

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了stat_count() must not be used with a y aesthetic相关的知识,希望对你有一定的参考价值。

stat_count() must not be used with a y aesthetic

目录

stat_count() must not be used with a y aesthetic

#仿真数据

#问题

解决:

完整错误:


#仿真数据

data_country <- data.frame(country = c("China", "Germany", "UK", "US"), 
            conversion_rate = c(0.001331558,0.062428188, 0.052612025, 0.037800687))



#问题

library(dplyr)
 library(ggplot2)

 #Investigate data further to build a machine learning model
 data_country = data %>%
           group_by(country) %>%
           summarise(conversion_rate = mean(converted))
  #Ist method
  qplot(country, conversion_rate, data = data_country,geom = "bar", stat ="identity", fill =   country)
  #2nd method
  ggplot(data_country)+aes(x=country,y = conversion_rate)+geom_bar()

解决:

data_country <- data.frame(country = c("China", "Germany", "UK", "US"), 
            conversion_rate = c(0.001331558,0.062428188, 0.052612025, 0.037800687))
ggplot(data_country, aes(x=country,y = conversion_rate)) +geom_bar(stat = "identity")

完整错误:

> library(dplyr)
> library(ggplot2)

> #Investigate data further to build a machine learning model
> data_country = data %>%
+     group_by(country) %>%
+     summarise(conversion_rate = mean(converted))
Error in UseMethod("group_by") : 
  no applicable method for 'group_by' applied to an object of class "function"
> #Ist method
> qplot(country, conversion_rate, data = data_country,geom = "bar", stat ="identity", fill =   country)
Error: stat_count() can only have an x or y aesthetic.
Run `rlang::last_error()` to see where the error occurred.
In addition: Warning message:
`stat` is deprecated 
> #2nd method
> ggplot(data_country)+aes(x=country,y = conversion_rate)+geom_bar()
Error: stat_count() can only have an x or y aesthetic.
Run `rlang::last_error()` to see where the error occurred.

参考:R

参考:R ggplot2: stat_count() must not be used with a y aesthetic error in Bar graph

以上是关于stat_count() must not be used with a y aesthetic的主要内容,如果未能解决你的问题,请参考以下文章

FLinkAssigned key must not be null

总结:TypeError: must be real number, not str

python TypeError: must be str, not bytes错误

TypeError: string indices must be integers, not str

TypeError: write() argument must be str, not bytes

TypeError: write() argument must be str, not bytes报错