R 使用geom_条与stat_标识构建ggplot

R 使用geom_条与stat_标识构建ggplot,r,ggplot2,R,Ggplot2,为什么会这样 library(ggplot2) 还有这个 ggplot(iris) + geom_bar(aes(x=Species,y=Sepal.Length),stat="identity") 有不同的y轴吗?我只是在测试它们的用法是否相同 ggplot(iris) + stat_identity(aes(x=Species,y=Sepal.Length),geom="bar") 在打印时,这两者的工作方式不同。从ggplot2文档: geom_bar使条形图的高度与每组病例数成

为什么会这样

library(ggplot2)

还有这个

ggplot(iris) + geom_bar(aes(x=Species,y=Sepal.Length),stat="identity")

有不同的y轴吗?我只是在测试它们的用法是否相同

ggplot(iris) + stat_identity(aes(x=Species,y=Sepal.Length),geom="bar")

在打印时,这两者的工作方式不同。从
ggplot2
文档:

geom_bar
使条形图的高度与每组病例数成比例,而
stat_identity
保持数据不变。这就是为什么你有两种不同的尺度

参见此处查看
geom\u栏

这里是
stat\u identity

默认的
位置不同:
几何图形条
“堆栈”
vs
统计标识
“标识”
。因此,条高为
tapply(iris$Sepal.Length,iris$Species,sum)
vs
tapply(iris$Sepal.Length,iris$Species,max)
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
ggplot2_2.2.1