R报错-错误: Aesthetics must be valid
2021-06-22 本文已影响0人
7f0a92cda77c
使用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,改完后,就出图了,没有报错,但是理解的对不对,就不是很清楚了
- count
- number of points in bin
- prop
- groupwise proportion
https://www.rdocumentation.org/packages/ggplot2/versions/3.3.3/topics/geom_bar