首页 > 解决方案 > 如何将列分解为 x 轴上直方图大小为 0.02 的倒数?

问题描述

如何在 R-Studio 的直方图的 x 轴上将列分解为大小为 0.02 的间隔?

eye = LEFTEYE$X__1
breaks = seq(0.04, 1.08, by=0.02)
eye.cut = cut(eye, breaks, right=FALSE)

eye.freq = table(eye.cut)
cbind(eye.freq)

hist(eye.freq, xlab="Cylindrical Power Measurements for the Left Eye")

在此处输入图像描述

标签: rstatisticshistogram

解决方案


您可以通过使用 hist() 中的中断参数来实现这一点。Breaks 采用 x 轴的上限和下限,然后是带有参数 by 的 bin 宽度。

例如,此代码使用 iris 数据集并将 x 轴的下限设置为 4,将上限设置为 8,并将 bin 宽度设置为 0.02。

hist(iris$Sepal.Length, breaks=seq(4,8,by=0.02))

直方图示例


推荐阅读