R:ggplot2 中的条形图,其中给出了每个条形的高度
R: barplot in ggplot2 where the height of each bar is given
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
构建此条形图,其中每个条的高度已经给出?
使用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')
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
构建此条形图,其中每个条的高度已经给出?
使用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')