library(ggplot2)
mydat <- data.frame(type = c("A", "B", "C"),
height = c(0.9, 0.3, 0.4))
ggplot(mydat, aes(x = type, y = height, fill = type)) +
geom_bar()
运行上面的代码会出现以下错误:
Error: stat_count() must not be used with a y aesthetic.
我想创建一个包含3条条形图的条形图:一条用于A,一条用于B,一条用于C。条形图的y轴范围从0到1,框图的高度分别为0.9、0.3和0.4。是否可以使用geom_bar
构建此条形图,其中每个条形图的高度都已给定?
发布于 2020-12-09 14:10:18
使用geom_col
:
library(ggplot2)
ggplot(mydat, aes(x = type, y = height)) + geom_col()
要使用geom_bar
,您需要指定stat = 'identity'
。
ggplot(mydat, aes(x = type, y = height)) + geom_bar(stat = 'identity')
https://stackoverflow.com/questions/65211337
复制相似问题