[英]Building ggplot using geom_bar vs stat_identity
library(ggplot2)
为什么这样
ggplot(iris) + geom_bar(aes(x=Species,y=Sepal.Length),stat="identity")
和这个
ggplot(iris) + stat_identity(aes(x=Species,y=Sepal.Length),geom="bar")
有不同的y轴? 我只是在测试它们的用法是否相等。
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
绘图时,这两种工具的工作方式有所不同。 从ggplot2
文档中:
geom_bar
使条形的高度与每个组中的案例数成正比,而stat_identity
使数据保持不变。 这就是为什么您有两个不同的比例。
在此处查看geom_bar
http://ggplot2.tidyverse.org/reference/geom_bar.html
此处为stat_identity
http://ggplot2.tidyverse.org/reference/stat_identity.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.