Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何适当地合并 R 中的 hist() 和 tapply() 函数,以获得数据子集的直方图?当我尝试使用标准的 tapply() 公式tapply(X, INDEX, FUN)时,我成功地获得了每个数据子集的值输出,但我只得到一个标题为“X[[4L]] 直方图”的直方图。如何获得每个子集的单独直方图?谢谢,
tapply(X, INDEX, FUN)
尝试这个:
par(mfrow = c(2, 2)) tapply(iris$Sepal.Length, iris$Species, hist)
但是,对于多面板图,您可能会发现 lattice 或 ggplot2 更合适。
library(lattice) histogram(~ Sepal.Length | Species, iris)
library(ggplot2) ggplot(iris, aes(Sepal.Length)) + geom_histogram() + facet_wrap(~ Species)