首页 > 解决方案 > 限制 SAS 生成的直方图中的条形数量

问题描述

我在 SAS 中运行 proc sgplot 来创建直方图。Y 轴:人数,X 轴:英里数。问题是直方图使用 30+ 条非常小的 x 轴间隔来显示数据。我只想在直方图中显示 10 个条形图。我可以在代码中添加一个简单的功能来限制直方图只显示 10 条吗?下面的代码:

    proc sgplot data= miles;
    title "Cumulative Miles Driven by Number of Individuals"
    histogram CumulativeMiles/scale= count
    fillattrs=(color=blue);
    xaxis values= (0 to 1000 by 100)
    label= "Cumulatve Miles Driven"
    yaxis values= (0 to 50000 by 10000)
    label= "Number of Individuals";
    run;

标签: sashistogramsgplot

解决方案


NBINS=10声明上的选项HISTOGRAM

NBINS=numeric-value 指定 bin 的数量。系统确定 BINWIDTH= 值。箱总是跨越数据的范围。

该过程尝试生成易于解释的刻度值(例如,5、10、15、20)。该过程有时会相应地调整第一个 bin 的位置和 bin 宽度。因此,图中显示的 bin 数量可能与 NBINS= 指定的数量不完全匹配。

或指定 BINWIDTH 和/或 BINSTART 选项。请参阅此处的绘图选项。


推荐阅读