美文网首页
R报错-错误: Aesthetics must be valid

R报错-错误: Aesthetics must be valid

作者: 7f0a92cda77c | 来源:发表于2021-06-22 14:59 被阅读0次

使用ggplot画图geom_bar出现了报错信息

报错信息
原因总结-y给的值是geom_bar()无法统计到的
geom_bar: Bar charts

Description
There are two types of bar charts: geom_bar() and geom_col(). geom_bar() makes the height of the bar proportional to the number of cases in each group (or if the weight aesthetic is supplied, the sum of the weights). If you want the heights of the bars to represent values in the data, use geom_col() instead. geom_bar() usesstat_count() by default: it counts the number of cases at each x position. geom_col() uses stat_identity(): it leaves the data as is.

geom_bar(
  mapping = NULL,
  data = NULL,
  stat = "count",
  position = "stack",
  ...,
  width = NULL,
  na.rm = FALSE,
  orientation = NA,
  show.legend = NA,
  inherit.aes = TRUE
)

geom_col(
  mapping = NULL,
  data = NULL,
  position = "stack",
  ...,
  width = NULL,
  na.rm = FALSE,
  show.legend = NA,
  inherit.aes = TRUE
)
stat_count(
  mapping = NULL,
  data = NULL,
  geom = "bar",
  position = "stack",
  ...,
  width = NULL,
  na.rm = FALSE,
  orientation = NA,
  show.legend = NA,
  inherit.aes = TRUE
)
ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut))#默认 stat = "count"

ggplot(data = diamonds) + 
  stat_count(mapping = aes(x = cut))#默认 图形 geom = "bar",
count改为prop
ggplot(data = diamonds) + 
  geom_bar(mapping = aes(x = cut, y = ..prop.., group = 1))

y=..prop..这个参数只有默认的几个,贴合这个就两个,1和3,改完后,就出图了,没有报错,但是理解的对不对,就不是很清楚了

  1. count
  2. number of points in bin
  3. prop
  4. groupwise proportion

https://www.rdocumentation.org/packages/ggplot2/versions/3.3.3/topics/geom_bar

相关文章

网友评论

      本文标题:R报错-错误: Aesthetics must be valid

      本文链接:https://www.haomeiwen.com/subject/rszpyltx.html