Re: [R] How to use breaks argument in hist() function correctly?
> When I had breaks = 18, I get total number of cells as 16, which is > same when I put breaks = 20 > > In the 2nd case I was expecting total number of cells (i.e. bars) as > 20 i.e. if I understand the documentation correctly I should expect > total number of cells (bars) should be same as breaks argument in > hist() function. You do not _quite_ understand the documentation correctly. ?hist says "In the last three cases the number is a suggestion only; as the breakpoints will be set to 'pretty' values" That includes specification of a single number of breaks. > How to make that happen? Specify a vector of breaks with 20 intervals (21 values). For example, breaks=seq(-450, 350, length.out=21) This gives a bin width of 4e5. S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use breaks argument in hist() function correctly?
Hi Cristofer, If you just ask for a number of breaks, you will get what "hist" thinks you should. Try this or something similar: hist(x,breaks=seq(min(x),max(x),length.out=21)) Jim On Wed, Sep 18, 2019 at 8:55 PM Christofer Bogaso wrote: > > Hi, > > I have a numerical vector as below > > x = c(92958.2014593977, -379826.025677203, 881937.411562002, 25761.5278163719, > -11837.158273897, 48450.8089746788, -415505.62910869, -168462.98512054, > 328504.255373387, -298966.051027528, 237133.794811816, -49610.1148173768, > -92459.1170329526, -261611.557495123, -314388.27876, -432257.362693919, > -1031328.04402229, 79654.3696754137, 107072.114744956, -43384.1420067487, > 410881.767122128, 1107540.47690119, -187319.627164858, -363126.966946238, > 264885.548330589, -127020.002396109, 150315.10537545, 609502.016523236, > 218679.801620448, 901573.599806465, 8289.59210428538, -860908.637977889, > 39680.5921457494, -70270.7462533897, 1135442.61429015, 133964.991179536, > 1603815.51357657, 2509929.42959337, 193680.587201446, -167020.153065672, > -55258.5415736386, -121185.161514792, -1003115.2769274, 1345368.12703686, > 91665.388397883, 137350.320344812, 29866.332965572, 558999.444304371, > 523687.79187, -867194.523170726, -271190.308507375, -423629.796389981, > 96407.0505512169, 193397.770743584, -1231855.39144784, 324272.89909045, > -1586859.60653751, 252986.272621096, -1008329.14877038, -24090.2255466315, > 159815.745712707, 969037.929787668, -586905.922684562, 573133.370665267, > -285493.361916026, -368392.707593945, -199242.654709143, 151002.480443041, > -678758.615800119, 467477.65504, -267683.37512503, -1541813.6353232, > -6723.49019530666, 373.233886695949, 59116.2440402955, -1369030.26511923, > 1527024.1822942, 63951.299612343, -535128.407281035, 304507.377244809, > 141771.552178838, 98963.774668207, 10810.9015935012, 1022008.90830883, > 276804.330003406, -304607.247552493, -15767.6578367545, -204454.923166458, > 722866.275157944, 137685.886832198, 590201.29119819, 904805.824902981, > -47417.8588758472, 55097.1936075327, 144426.170076371, 1020559.38779514, > -7019.11334737329, 488224.043025845, -28272.5766026849, -295384.449673914, > -93475.8799719289, -367939.725072447, -1244135.36327203, -863835.124327735, > -1399240.55792133, 241146.794430078, -96612.1109580967, -9159.41140641969, > -240291.731366074, -7482.02181888149, 71427.8225121907, -228401.89341468, > 948738.649629141, -327368.940001115, -53374.866091836, 126448.573738739, > 344962.4459403, 270571.141270723, 746988.197131718, -253220.465177424, > -362652.833437272, -4385.56796251462, -114398.64639441, 454240.63525686, > -1239567.92855698, -389939.987378005, -364083.196493484, 24693.1882238397, > 4635.22406457209, 57992.688805147, -67934.5184434773, 123034.937557127, > 483909.751375248, -167441.867070132, -382537.019103907, 267584.10264059, > -188944.743935369, -47062.5409102427, -860201.712919788, -203096.090898701, > 44317.9727734545, 375924.206160012, 67000.7086638517, 137607.783105903, > -306430.502044082, -669552.84790218, -72629.0354820569, 251145.827045551, > -230557.16727732, -112594.52630222, 74052.4425890159, -105774.458850881, > -241185.430318678, -296663.488112722, 156807.699193046, -520102.742784345, > -56451.5201730288, -23171.0259034268, -107945.719878344, -158480.929620835, > -769507.414580615, -83077.050717928, 477248.698330914, 27706.3803488034, > 70485.7144565997, 302213.341425514, -322119.331851626, -476228.406727923, > -99453.524756431, -673693.791106482, 38765.0473434452, 63302.3087165867, > 116619.019966859, -167803.424492692, 82982.1864557734, -262627.809345438, > 643538.235642472, -90724.2065826313, -435531.286293254, -371820.753318447, > -224713.223837607, -538987.838068522, -195841.454277966, 13924.6120356087, > -415252.7309228, 209424.879456433, 485624.048364534, 74317.8482029741, > 19994.939065553, -460452.302259829, -141374.457424938, -77310.8968822459, > 56112.3979095014, -150891.122921784, -679395.088755517, -523803.739201696, > -69888.2239139985, -4463.34352237508, -63616.8025699607, 906704.585396864, > 1096575.89875834, -382869.397851591, -624324.630106468, -468837.009485095, > -49963.2943695135, 17038.2753380311, 756286.614911188, -995536.510249994, > 308899.601761641, -375123.707808525, -113921.428586057, -61573.6957341075, > 55239.3511454715, -46731.8391379398, 697843.754042485, 265162.29364751, > 1133747.94683337, -355974.319924194, 30699.0482856455, -19680.791041683, > -624454.313911307, 94983.7375389124, 744849.080038272, 172732.610815633, > -120546.157860821, 62579.2205127864, -621204.554941904, 293869.359181081, > -108505.317455271, 646163.583792489, -502636.630380265, 502413.155645464, > -49238.362688755, 108812.985894042, -139113.621347874, 1120034.73283877, > -296008.55142246, -845627.626734492, 116082.364002893, 85096.4224949463, > -84149.6401610159, 611729.398657364, -783642.839894851, -9788.4825023263, > -58734.3009729933, -110950.384570162, -53258.3833170316, -20519.0858192393, >
[R] How to use breaks argument in hist() function correctly?
Hi, I have a numerical vector as below x = c(92958.2014593977, -379826.025677203, 881937.411562002, 25761.5278163719, -11837.158273897, 48450.8089746788, -415505.62910869, -168462.98512054, 328504.255373387, -298966.051027528, 237133.794811816, -49610.1148173768, -92459.1170329526, -261611.557495123, -314388.27876, -432257.362693919, -1031328.04402229, 79654.3696754137, 107072.114744956, -43384.1420067487, 410881.767122128, 1107540.47690119, -187319.627164858, -363126.966946238, 264885.548330589, -127020.002396109, 150315.10537545, 609502.016523236, 218679.801620448, 901573.599806465, 8289.59210428538, -860908.637977889, 39680.5921457494, -70270.7462533897, 1135442.61429015, 133964.991179536, 1603815.51357657, 2509929.42959337, 193680.587201446, -167020.153065672, -55258.5415736386, -121185.161514792, -1003115.2769274, 1345368.12703686, 91665.388397883, 137350.320344812, 29866.332965572, 558999.444304371, 523687.79187, -867194.523170726, -271190.308507375, -423629.796389981, 96407.0505512169, 193397.770743584, -1231855.39144784, 324272.89909045, -1586859.60653751, 252986.272621096, -1008329.14877038, -24090.2255466315, 159815.745712707, 969037.929787668, -586905.922684562, 573133.370665267, -285493.361916026, -368392.707593945, -199242.654709143, 151002.480443041, -678758.615800119, 467477.65504, -267683.37512503, -1541813.6353232, -6723.49019530666, 373.233886695949, 59116.2440402955, -1369030.26511923, 1527024.1822942, 63951.299612343, -535128.407281035, 304507.377244809, 141771.552178838, 98963.774668207, 10810.9015935012, 1022008.90830883, 276804.330003406, -304607.247552493, -15767.6578367545, -204454.923166458, 722866.275157944, 137685.886832198, 590201.29119819, 904805.824902981, -47417.8588758472, 55097.1936075327, 144426.170076371, 1020559.38779514, -7019.11334737329, 488224.043025845, -28272.5766026849, -295384.449673914, -93475.8799719289, -367939.725072447, -1244135.36327203, -863835.124327735, -1399240.55792133, 241146.794430078, -96612.1109580967, -9159.41140641969, -240291.731366074, -7482.02181888149, 71427.8225121907, -228401.89341468, 948738.649629141, -327368.940001115, -53374.866091836, 126448.573738739, 344962.4459403, 270571.141270723, 746988.197131718, -253220.465177424, -362652.833437272, -4385.56796251462, -114398.64639441, 454240.63525686, -1239567.92855698, -389939.987378005, -364083.196493484, 24693.1882238397, 4635.22406457209, 57992.688805147, -67934.5184434773, 123034.937557127, 483909.751375248, -167441.867070132, -382537.019103907, 267584.10264059, -188944.743935369, -47062.5409102427, -860201.712919788, -203096.090898701, 44317.9727734545, 375924.206160012, 67000.7086638517, 137607.783105903, -306430.502044082, -669552.84790218, -72629.0354820569, 251145.827045551, -230557.16727732, -112594.52630222, 74052.4425890159, -105774.458850881, -241185.430318678, -296663.488112722, 156807.699193046, -520102.742784345, -56451.5201730288, -23171.0259034268, -107945.719878344, -158480.929620835, -769507.414580615, -83077.050717928, 477248.698330914, 27706.3803488034, 70485.7144565997, 302213.341425514, -322119.331851626, -476228.406727923, -99453.524756431, -673693.791106482, 38765.0473434452, 63302.3087165867, 116619.019966859, -167803.424492692, 82982.1864557734, -262627.809345438, 643538.235642472, -90724.2065826313, -435531.286293254, -371820.753318447, -224713.223837607, -538987.838068522, -195841.454277966, 13924.6120356087, -415252.7309228, 209424.879456433, 485624.048364534, 74317.8482029741, 19994.939065553, -460452.302259829, -141374.457424938, -77310.8968822459, 56112.3979095014, -150891.122921784, -679395.088755517, -523803.739201696, -69888.2239139985, -4463.34352237508, -63616.8025699607, 906704.585396864, 1096575.89875834, -382869.397851591, -624324.630106468, -468837.009485095, -49963.2943695135, 17038.2753380311, 756286.614911188, -995536.510249994, 308899.601761641, -375123.707808525, -113921.428586057, -61573.6957341075, 55239.3511454715, -46731.8391379398, 697843.754042485, 265162.29364751, 1133747.94683337, -355974.319924194, 30699.0482856455, -19680.791041683, -624454.313911307, 94983.7375389124, 744849.080038272, 172732.610815633, -120546.157860821, 62579.2205127864, -621204.554941904, 293869.359181081, -108505.317455271, 646163.583792489, -502636.630380265, 502413.155645464, -49238.362688755, 108812.985894042, -139113.621347874, 1120034.73283877, -296008.55142246, -845627.626734492, 116082.364002893, 85096.4224949463, -84149.6401610159, 611729.398657364, -783642.839894851, -9788.4825023263, -58734.3009729933, -110950.384570162, -53258.3833170316, -20519.0858192393, 456910.655858686, 48830.1071552214, -358333.95721609, 80046.3518406906, -224193.119044228, 45897.0722281932, -4895.48804178487, 735710.318540904, 183571.602770915, -103173.288434665, 554285.106452708, 536724.819749035, -38962.2828892764, 26730.2338615816, -267784.282389664, 659763.691652086, 331635.73797362, -305496.497141735, 337703.432388682, 26793.2725583163, -214055.61511956,