2016-07-05 49 views
1

我需要规格化0-1之间的直方图的Y轴。如何正常化0和1之间的直方图的Y轴?

这是我data.frame的一部分:

1.8064 2.2016 2.4506 2.1828 2.1171 1.9308 2.1707 2.1885 
2.2310 2.2400 1.9115 2.1527 2.0934 1.7989 2.2144 2.0091 
1.9248 2.2038 1.9676 1.9224 1.9502 1.7990 2.0824 2.1300 
2.0095 2.0341 1.8433 1.8361 1.9958 1.8243 2.0397 2.0482 
2.1143 2.2627 1.7620 1.7561 1.9490 1.9803 1.9336 2.2511 
2.2377 2.5414 1.7867 1.6618 2.5090 1.8325 2.0212 2.1616 
2.3476 2.1878 2.0469 1.7508 2.2969 1.7939 2.0291 2.0721 
2.3534 2.0932 2.3502 1.9960 2.0710 1.9923 1.7787 1.9772 
2.2607 2.1504 2.3685 2.1148 2.1961 1.7738 1.8405 2.0135 
2.2411 1.9916 2.4726 2.0347 2.0751 1.7570 1.8874 1.9385 
2.1913 1.8981 2.2441 2.3068 2.1198 2.1484 1.8056 1.7747 
2.0842 1.8750 2.3023 2.1204 1.8972 2.1534 1.8028 1.9401 
2.2105 1.9618 2.2472 1.9656 2.3098 1.9771 1.9520 1.8627 
2.2863 1.9959 2.1781 1.9544 1.9281 1.9286 1.9699 2.0330 
2.1987 2.0583 2.0953 2.0206 2.1148 2.3789 1.7052 1.9145 
2.0513 2.0850 1.9810 2.4943 1.9120 2.2209 1.9461 2.0882 
2.0049 2.0416 1.9303 2.3681 1.8974 2.0054 1.9261 1.9097 
1.6882 2.1196 1.8641 2.3600 2.0931 1.7641 2.1131 1.7748 
1.8840 1.7604 1.7664 2.2000 2.0055 1.8229 1.9871 1.9168 
1.7340 1.9656 1.8480 2.0523 1.9950 1.8716 1.9206 1.7786 

这是我在做什么目前:

for (i in data){ 
    x <- i 

    h<-hist(x, plot = FALSE) 
    h$density = h$counts/sum(h$counts) 

    plot(h, col="red", xlim = c(0,max(data)))} 

,但我得到这样的画面:

enter image description here

但我真正想要的是这样的(Y轴在0-1之间):

enter image description here

+1

使用scale()函数(http://www.inside-r.org/r-doc/base/scale) – elbaulp

+0

@ algui91 scale where ?.我不想调整我的数据框,我想调整频率。有没有办法做到这一点?我有点新手在R – Enrique

+0

看看这个答案:http://stackoverflow.com/questions/15215457/standardize-data-columns-in-r – elbaulp

回答

1

要缩放[0,1]之间的y您可以使用什么flodelthis answer

maxs <- apply(a, 2, max) 
mins <- apply(a, 2, min) 
scale(a, center = mins, scale = maxs - mins) 

建议,但修改的代码只使用您的y柱:

maxs <- max(y) 
mins <- min(y) 
scale(y, center = mins, scale = maxs - mins) 

希望它帮助

0

只需将每个观察值除以最大值即可将数据归一化为1.

但问题仍然存在,为什么?如果y轴归一化为0-1,则意味着概率,这显然不是。

相关问题