从值向量创建直方图

时间:2017-04-14 16:26:26

标签: r

这是我的价值观

> blufile2$Vf2[blufile2$Site == '2']
   [1] 2.918530 2.925320 2.926210 2.918510 2.912310 2.908160 2.906990 2.906940 2.907420 2.909130 2.909860 2.911250
  [13] 2.913300 2.911280 2.908770 2.907380 2.906760 2.905330 2.904420 2.904360 2.904270 2.905800 2.907190 2.909450
  [25] 2.911710 2.910800 2.908600 2.906340 2.904930 2.904310 2.906800 2.902590 2.901020 2.900790 2.901090 2.903160
  [37] 2.904630 2.905280 2.905690 2.905210 2.904590 2.904180 2.903830 2.904180 2.904630 2.904790 2.905080 2.906510
  [49] 2.906590 2.908440 2.908000 2.909910 2.912100 2.912280 2.908980 2.907530 2.906780 2.906790 2.906070 2.906360
  [61] 2.905570 2.905720 2.905030 2.904710 2.904710 2.904950 2.904390 2.904430 2.904170 2.903650 2.902390 2.901870
  [73] 2.900900 2.900420 2.900860 2.902570 2.904360 2.908180 2.903970 2.901810 2.901150 2.900990 2.901170 2.901690
  [85] 2.902480 2.902580 2.903010 2.903860 2.903950 2.904230 2.904690 2.905340 2.904810 2.905210 2.905620 2.905960
  [97] 2.905990 2.906530 2.907020 2.906850 2.907630 2.907560 2.908310 2.907720 2.908350 2.909980 2.911580 2.911870
 [109] 2.909250 2.907820 2.907040 2.907550 2.907670 2.907640 2.907500 2.907550 2.907560 2.907350 2.906540 2.905940
 [121] 2.906530 2.905710 2.905340 2.905660 2.905020 2.904990 2.904570 2.904860 2.904360 2.904400 2.903470 2.902930
 [133] 2.902430 2.902510 2.902280 2.902870 2.903100 2.904710 2.907120 2.906060 2.903750 2.902910 2.902930 2.902320
 [145] 2.902920 2.902930 2.903090 2.903890 2.904320 2.904350 2.904810 2.904480 2.905210 2.904950 2.905000 2.905220
 [157] 2.906160 2.906340 2.906580 2.906140 2.907250 2.907470 2.907520 2.907780 2.908330 2.908280 2.908350 2.908350
 [169] 2.908420 2.908410 2.908750 2.909980 2.911470 2.912010 2.909670 2.908960 2.908380 2.908360 2.908120 2.908800
 [181] 2.908690 2.908300 2.908490 2.908600 2.907930 2.907770 2.907330 2.906900 2.906940 2.906480 2.906660 2.906170
 [193] 2.906260 2.905990 2.905540 2.905980 2.906030 2.906080 2.905100 2.904800 2.904540 2.904210 2.904780 2.904100
 [205] 2.904340 2.903760 2.903650 2.904170 2.906420 2.906900 2.903870 2.902730 2.902820 2.903420 2.904810 2.904450
 [217] 2.905090 2.905230 2.905010 2.906010 2.905540 2.906490 2.906240 2.906260 2.906270 2.906320 2.906310 2.907060
 [229] 2.906730 2.907010 2.907600 2.907450 2.907940 2.908010 2.908540 2.908750 2.908630 2.908580 2.909150 2.909470
 [241] 2.909410 2.909580 2.909010 2.909060 2.909810 2.911170 2.912880 2.913690 2.910960 2.909990 2.908870 2.909390
 [253] 2.908710 2.908750 2.909180 2.909170 2.909290 2.909580 2.909010 2.908520 2.908440 2.908240 2.908400 2.907660
 [265] 2.907220 2.907520 2.907170 2.907360 2.907310 2.907160 2.907170 2.907470 2.907520 2.906900 2.906720 2.906870
 [277] 2.905830 2.905820 2.906420 2.906340 2.906110 2.905120 2.904550 2.904270 2.903170 2.904860 2.908510 2.910470
 [289] 2.905080 2.903010 2.903090 2.904420 2.905280 2.905900 2.906430 2.906660 2.892680 2.906910 2.906300 2.907000
 [301] 2.906740 2.907610 2.907040 2.907800 2.907300 2.907820 2.907570 2.907240 2.907810 2.907860 2.908120 2.908590
 [313] 2.908150 2.908650 2.908880 2.909360 2.909460 2.909620 2.909850 2.909670 2.909780 2.909570 2.910070 2.910480
 [325] 2.911110 2.914660 2.911420 2.909380 2.909980 2.909120 2.908890 2.908990 2.909020 2.908880 2.908580 2.908560
 [337] 2.909060 2.908980 2.908430 2.908810 2.908310 2.908130 2.908000 2.908010 2.907640 2.907370 2.907370 2.907470
 [349] 2.907430 2.907220 2.907560 2.907340 2.907610 2.907220 2.907620 2.906710 2.906490 2.906610 2.906050 2.906700
 [361] 2.903800 2.905650 2.904740 2.903980 2.904180 2.904310 2.904660 2.907720 2.909380 2.905250 2.903320 2.903780
 [373] 2.903860 2.904510 2.904660 2.905170 2.905600 2.905660 2.905720 2.906250 2.906660 2.906560 2.907040 2.906690
 [385] 2.907640 2.906930 2.906800 2.906400 2.907200 2.907300 2.906890 2.907420 2.907780 2.907840 2.908120 2.907750
 [397] 2.908070 2.908490 2.908510 2.908470 2.908170 2.908230 2.908730 2.908730 2.908500 2.909380 2.909420 2.908990
 [409] 2.909380 2.908620 2.909690 2.911380 2.913350 2.909630 2.907810 2.907380 2.907630 2.908210 2.908630 2.908150
 [421] 2.908070 2.907480 2.907780 2.907880 2.907870 2.908210 2.907910 2.907700 2.907800 2.907360 2.908080 2.907660
 [433] 2.907450 2.907320 2.907070 2.906670 2.906920 2.907080 2.906620 2.907650 2.907240 2.907360 2.907140 2.906650
 [445] 2.906930 2.906490 2.906050 2.906820 2.906750 2.905400 2.905470 2.905170 2.904530 2.903830 2.904200 2.904150
 [457] 2.907060 2.907600 2.903570 2.902810 2.902880 2.903760 2.904090 2.904850 2.905070 2.905540 2.905640 2.906040
 [469] 2.906310 2.905770 2.905980 2.905990 2.906750 2.906310 2.906640 2.906050 2.905740 2.906000 2.906120 2.906180
 [481] 2.906360 2.906490 2.906670 2.907040 2.907450 2.906760 2.907320 2.907270 2.907420 2.907460 2.907900 2.907500
 [493] 2.907280 2.908270 2.907870 2.908370 2.908120 2.908050 2.907940 2.907820 2.907750 2.908750 2.910520 2.911660
 [505] 2.908530 2.907630 2.907500 2.907030 2.907340 2.907760 2.907660 2.907270 2.907180 2.906750 2.907510 2.907440
 [517] 2.906890 2.907270 2.906610 2.907400 2.907020 2.907260 2.907050 2.906920 2.906470 2.905910 2.905710 2.905670
 [529] 2.905530 2.905030 2.905010 2.905730 2.905870 2.906100 2.905860 2.906150 2.905700 2.906760 2.905850 2.906210
 [541] 2.905390 2.906050 2.905300 2.905230 2.904170 2.903600 2.903130 2.902620 2.902540 2.904650 2.902340 2.901930
 [553] 2.900730 2.900670 2.901450 2.902010 2.903480 2.903580 2.904390 2.904910 2.904600 2.905460 2.905090 2.905080
 [565] 2.905500 2.904460 2.904400 2.904320 2.904070 2.904320 2.903810 2.904240 2.904110 2.904410 2.904790 2.905360
 [577] 2.905330 2.905840 2.905540 2.906010 2.906430 2.906590 2.906660 2.906740 2.907080 2.906330 2.907150 2.907430
 [589] 2.907190 2.907490 2.907670 2.907800 2.907580 2.907750 2.907200 2.907550 2.908030 2.910340 2.908250 2.907090
 [601] 2.907130 2.906970 2.907050 2.907270 2.907160 2.907370 2.907380 2.906700 2.906930 2.906800 2.906620 2.906010
 [613] 2.905860 2.905450 2.905870 2.905880 2.905150 2.905990 2.904760 2.904550 2.904100 2.904620 2.904090 2.903580
 [625] 2.903720 2.903710 2.903830 2.903600 2.904520 2.904800 2.904700 2.905500 2.905160 2.905320 2.904240 2.904470
 [637] 2.903620 2.903060 2.902520 2.901130 2.900600 2.901630 2.903630 2.901450 2.899390 2.902560 2.900080 2.900290
 [649] 2.900860 2.901740 2.902910 2.902800 2.903570 2.903570 2.903680 2.903440 2.902870 2.902690 2.902640 2.902930
 [661] 2.902410 2.902510 2.903150 2.903030 2.903270 2.903470 2.903790 2.903760 2.904490 2.904720 2.904440 2.904880
 [673] 2.905160 2.904910 2.904620 2.905230 2.905310 2.905850 2.906090 2.906480 2.906600 2.906460 2.907130 2.907310
 [685] 2.907400 2.907550 2.907760 2.907200 2.907530 2.906870 2.907340 2.910230 2.909090 2.906170 2.906150 2.906410
 [697] 2.906830 2.907310 2.906560 2.907180 2.906520 2.906650 2.906440 2.906030 2.905500 2.905550 2.905060 2.904770
 [709] 2.904570 2.904470 2.904940 2.904500 2.904580 2.905090 2.903960 2.903790 2.903350 2.903450 2.903330 2.903160
 [721] 2.884220 2.902290 2.901990 2.902250 2.902070 2.902130 2.902220 2.902890 2.902850 2.903490 2.903150 2.903160
 [733] 2.903030 2.901900 2.901790 2.900840 2.900150 2.899850 2.899280 2.899620 2.900310 0.347089 2.902060 2.898970
 [745] 2.897680 2.897610 2.897870 2.899050 2.899360 2.900460 2.900430 2.901370 2.901560 2.901630 2.902330 2.901470
 [757] 2.901880 2.900830 2.901520 2.901590 2.901560 2.901020 2.901080 2.901570 2.901940 2.902710 2.902400 2.902660
 [769] 2.903130 2.903260 2.904110 2.903780 2.904190 2.904230 2.903780 2.904450 2.904130 2.904580 2.905630 2.905440
 [781] 2.906280 2.906370 2.906690 2.906820 2.906470 2.906730 2.907140 2.907200 2.906350 2.906220 2.905830 2.907160
 [793] 2.905490 2.904100 2.905390 2.906010 2.906400 2.906480 2.906350 2.906470 2.906700 2.906110 2.906080 2.905500
 [805] 2.904650 2.904400 2.904220 2.903960 2.904040 2.903880 2.904140 2.903620 2.903500 2.903770 2.903230 2.903060
 [817] 2.902740 2.902070 2.901810 2.901810 2.901330 2.901230 2.901270 2.901100 2.901550 2.901590 2.901010 2.901550
 [829] 2.901340 2.901790 2.900810 2.901550 2.901070 2.900320 2.899760 2.899070 2.899480 2.898110 2.898410 2.897350
 [841] 2.898530 2.901110 2.900640 2.897110 2.896120 2.896530 2.896900 2.897610 2.897200 2.898230 2.898860 2.899430
 [853] 2.899950 2.899910 2.900470 2.899570 2.899870 2.900900 2.900010 2.899990 2.900300 2.900310 2.900280 2.900900
 [865] 2.901180 2.901330 2.901110 2.901430 2.901880 2.903180 2.903210 2.903070 2.903620 2.903610 2.903750 2.903590
 [877] 2.903580 2.903870 2.904830 2.906110 2.906210 2.906180 2.906000 2.905900 2.906190 2.906220 2.906260 2.906480
 [889] 2.906150 2.905100 2.903960 2.904730 2.904700 2.903880 2.904770 2.905900 2.905690 2.905670 2.905610 2.905740
 [901] 2.905350 2.905110 2.905390 2.905140 2.904490 2.904270 2.903820 2.903270 2.903490 2.903370 2.903460 2.903030
 [913] 2.903380 2.903040 2.902320 2.901410 2.899770 2.899790 2.899760 2.900710 2.900510 2.900400 2.900190 2.900290
 [925] 2.900280 2.900170 2.899470 2.899710 2.899890 2.899750 2.899720 2.898950 2.899220 2.898730 2.898380 2.897760
 [937] 2.898170 2.896960 2.896710 2.896690 2.897340 2.900120 2.900170 2.896660 2.895890 2.896140 2.896100 2.896510
 [949] 2.897490 2.897060 2.897290 2.898810 2.897910 2.898700 2.899140 2.899580 2.898790 2.898530 2.899380 2.898920
 [961] 2.899630 2.899500 2.899710 2.899000 2.899560 2.900140 2.900180 2.902010 2.903400 2.902940 2.902610 2.903330
 [973] 2.903190 2.903260 2.903790 2.903540 2.904570 2.904810 2.905310 2.905660 2.905680 2.905330 2.906140 2.906160
 [985] 2.906000 2.905320 2.904300 2.903890 2.904590 2.904080 2.903360 2.904560 2.904950 2.905650 2.905740 2.905820
 [997] 2.905480 2.904820 2.904980 2.905240

我想将此向量转换为直方图,然后使用以下代码

绘制结果
P2 <- hist(blufile2$Vf2[blufile2$Site == '2'], breaks=10, freq=TRUE, right=TRUE)
plot( P2, col=rgb(0,0,1,1/4))  # first histogram

然而,我得到以下情节 enter image description here

如何将向量与频率一起正确地分为二进制位?

1 个答案:

答案 0 :(得分:2)

您没有注意到,但是在索引742处(可能在原始数据中的更多位置),您的值远小于2,因此在进行直方图时,几乎所有数据都被分类到相同的位置bin(注意那个bin上的计数差不多是2000 - 这给出了什么是错误的提示)。

假设这是一个异常值,试着在没有它的情况下进行绘图:

P2 <- hist(blufile2$Vf2[(blufile2$Site == '2') & (blufile2$Vf2 > 1)], breaks=10, freq=TRUE, right=TRUE)
plot( P2, col=rgb(0,0,1,1/4))  # first histogram