使用hist()在R中绘制密度直方图

时间:2017-01-24 02:15:41

标签: r plot histogram

好吧所以我需要制作密度直方图。我有使用hist()函数在R中绘制直方图所需的所有数据。我的意思是&#34; 密度直方图是我希望密度在Y轴上类在x轴上。< /强>

这是我的数据:

<xarray.Dataset>
Dimensions:           (Time: 48, bottom_top: 50, bottom_top_stag: 51, 
soil_layers_stag: 4, south_north: 1015, south_north_stag: 1016, west_east: 1359, west_east_stag: 1360)
Coordinates:
XLAT              (Time, south_north, west_east) float32 18.1363 18.1456 ...
XLAT_U            (Time, south_north, west_east_stag) float32 18.1316 ...
XLAT_V            (Time, south_north_stag, west_east) float32 18.1198 ...
XLONG             (Time, south_north, west_east) float32 -122.884 ...
XLONG_U           (Time, south_north, west_east_stag) float32 -122.901 ...
XLONG_V           (Time, south_north_stag, west_east) float32 -122.879 ...
  * Time              (Time) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...
  * south_north       (south_north) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
  * west_east         (west_east) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...
  * bottom_top        (bottom_top) int64 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 ...

Data variables:
GRAUPEL_ACC_NC    (Time, south_north, west_east) float32 0.0 0.0 0.0 0.0 ...
P                 (Time, south_north, west_east) float32 101112.0 ...
PREC_ACC_NC       (Time, south_north, west_east) float32 0.0 0.0 0.0 0.0 ...
QVAPOR            (Time, south_north, west_east) float32 0.0120251 ...
SNOW_ACC_NC       (Time, south_north, west_east) float32 0.0 0.0 0.0 0.0 ...
TK                (Time, south_north, west_east) float32 295.372 295.367 ...
Z                 (Time, south_north, west_east) float32 0.0 0.0 0.0 0.0 ...

现在我在r中所做的是

我用所有这些数据加载了文件并写了

Class     Freq  ClassWidth  Density 
30.0-32.0   8   2.0             4.0 
32.0-33.0   7   1.0             7.0
33.0-34.0   10  1.0             10.0
34.0-34.5   25  0.5             50.0
34.5-35.0   30  0.5             60.0
35.0-35.5   40  0.5             80.0
35.5-36.0   45  0.5             90.0
36.0-50.0   5   14              0.357142857

有人可以帮助我解决我的问题。

谢谢

1 个答案:

答案 0 :(得分:2)

hist想要从原始数据计算自己的高度,但你可以用条形图得到你想要的东西。

barplot(data3$Density, names.arg=data3$Class, space=0, ylim=c(0,100))

Density Barplot