[R] histogram bin width

Francisco Zagmutt gerifalte28 at hotmail.com
Tue Nov 7 03:30:56 CET 2006


There are several ways to do this, probably the easiest is to use 
truehist from MASS. i.e

require(MASS)
par(mfrow=c(3,1)) #3 rows of histograms, one column
truehist(x,h=.05)
truehist(y,h=.05)
truehist(z,h=.05)


I hope this helps,


Francisco

-- 
Dr. Francisco J. Zagmutt
College of Veterinary Medicine and Biomedical Sciences
Colorado State University


Leeds, Mark (IED) wrote:
> hi all : i have the data below and then below that, i call the hist
> function three times using the Scott method for the widths of the bins. 
> the bin width is different for the three histograms but I would like it
> to always be 0.05 regfardless of the data
> set being histogrammed.
>  
> I'm sure there must be a manual way to do this which is fine with me. i
> tried breaks=0.05 but it wasn't happy with that because
> it wanted more than one value. maybe rep of some kind ? thanks for any
> ideas.
>  
> #-----------------------------------------------------------------------
> ------------------------------------------------------------------------
> --
>  
> x<-c(0.0128502370392525, -0.0406114936107649, 0.0502596250677279, 
> 0.0336802928825541, -0.0284365582306378, -0.0123162652859499, 
> 0, 0.0988440771231502, 0.000457303014833599, 0.0438008457360972, 
> -0.0295225689345813, 0.0326340659976054, 0.0114081996557935, 
> -0.00274027837328106, -0.103925054753873, 0.057782563686537, 
> -0.0215841904671166, 0.0403475083316174, -0.0488552849688517, 
> 0.052027860619841, 0.0073670290205996, 0.0536279975936971,
> 0.0567555433505618, 
> 0.069535452508962, -0.055240239022325, 0.0480899757183906,
> -0.0390747482838627, 
> -0.110381259381231, -0.0611602607279771, -0.027247284290155, 
> 0.00201215051465198, 0.0351015849923364, 0.000912458332802402, 
> -0.0356188783818823, -0.0151349715427074, -0.0107357188203316, 
> 0.00429507140617957, 0.0214550838644634, -0.00532586292427695, 
> -0.058472751173344, -0.00320685840140555, -0.0132752028606298, 
> 0.0798134030713271, 0.00639570209042262, 0.00733180515837262, 
> -0.00643049849253785, 0.00715640319484123, -0.0829161706061399, 
> -0.0534037801206644, 0.0153327381386070, 0.0284004808796645, 
> -0.0315058522597944, -0.0095737042330235, -0.0296729617912384, 
> -0.0030465605855845, -0.0748614641468137, 0.0166842475362472, 
> 0.037246992858897, 0.0450648619736427, 0.0469533676324296,
> 0.00783221961935254, 
> -0.0475450625769369, 0.00992104302435237, -0.0186071688883516, 
> 0.00955266971311985, 0.0228995009757149, -0.0511257997087178, 
> 0.0147078908099729, 0.0488245426407907, 0.0302791426006976,
> -0.00975113705994346, 
> 0.0292954447679072, -0.042853724755787, 0.0129855494898301,
> 0.0958562428873933, 
> -0.00294441161212688, 0.0898281173073556, -0.0126756100307546, 
> -0.0453902698039244, -0.00321585444229555, 0.0356899179770664, 
> 0.031308484621384, -0.0215662741815947, 0.000354673443325737, 
> -0.00130449103652452)
> 
> y<-c(0.127113797014822, -0.0527132197083446, -0.0230934065523769, 
> -0.00631932875867491, 0.0446227417141287, -0.0218546858530289, 
> 0.0487408833245162, 0.109421316066438, -0.00927640783636718, 
> -0.0247026288074714, 0.0432817808698083, -0.0630453038775514, 
> 0.111127744216866, -0.00307369805856439, -0.0418170289885111, 
> -0.00356492258806185, 0.0227847721326668, 0.0401574349545797, 
> -0.0886738669484188, -0.00987777704333226, 0.0033899536306059, 
> -0.0424711414981793, -0.0202601011768166, 0.0484301472245541, 
> 0.0626136210973627, 0.0643242186097126, -0.0980071359648171, 
> 0.126367348457546, 0.0153346351584815, -0.109692817544893,
> -0.00235925185982921, 
> 0.0769184869215955, -0.00409180113276619, -0.00445306007899049, 
> -0.0149701697632842, 0.0502466501891341, 0.0282876823353817, 
> 0.0534793377936715, -0.0308185450547782, 0.00544008331235801, 
> -0.0572797488928245, 0.0367878245006281, -0.0497845822930998, 
> -0.0570171933564012, -0.00516582291671952, -0.000716222071872608, 
> -0.00358170037682015, 0.0480195527640781, 0.0060224851272217, 
> 0.00254638667742668, 0.00637450199416634, 0.104503303131143, 
> 0.061429306685934, -0.0138576193376316, 0.064563814226215,
> 0.0460330593686997, 
> 0.0149459277962727, 0.0404914176123761, -0.0412218530692954, 
> -0.0593371756266947, -0.0397570408328995, 0.0163026336202243, 
> -0.0180931721866173, -0.0456516784920424, -0.0288938746995981, 
> -0.0295499885442752, -0.0141674163828931, 0.00892686014042354, 
> 0.0237862041138293, 0.0731246180484035, -0.0313725492769201, 
> -0.00209224717817591, -0.0169734460274462, 0.0171007097211628, 
> -0.285112534969834, 0.0100838247329094, -0.00228181664212457, 
> 0.000140945419602190, 0.00768223483573749, 0.0230504071513593, 
> 0.0371397775679405, -0.0361881281642162, 0.0106234928019866, 
> -0.0236259310807618, -0.0246891741169541)
> 
> z<-c(-0.00171047888493092, -0.00301867047713955, 0.0086865879136866, 
> -0.0537115412882372, -0.0195420954038461, -0.00524512203767813, 
> 0.0325249089459412, 0.111198630164910, 0.0178528236729925,
> 0.0413402809899210, 
> 0.116349808290739, 0.0512011287258751, -0.0218604390330945,
> 0.0153390225896111, 
> 0.0464780076971039, -0.00214304848649149, -0.0153031714176244, 
> -0.0285204376796244, 0.0241676523094370, 0.0611006871014119, 
> -0.0572726170836368, 0.0220219962936419, 0.0137447455739625, 
> 0.0125743870835748, 0.0439863214467984, -0.0420126985937408, 
> 0.05572139447656, 0.00531169310349355, 0.313720718069366,
> 0.0332787636253329, 
> -0.00312721372228708, -0.0245639367960848, 0.00206131023752221, 
> 0.055022414930228, 0.0388274126407850, -0.00751548727553342, 
> -0.000859029039457226, 0.0276388031815955, 0.0437009370680030, 
> -0.0187370071856208, -0.0861778005541325, 0.185871532665693, 
> 0.0149083668160799, -0.0276160266518666, -0.0301821711895300, 
> 0.0136393502816468, -0.0792402135848747, -0.0335761629617792, 
> -0.053127624425997, -0.0205010021466556, -0.0595770050389355, 
> 0.0103580846716689, -0.0247323048628623, 0.220829705493308,
> -0.0669960783488577, 
> 0.00958318471262487, -0.0060650891567704, -0.0228175126933294, 
> -0.0675935755936052, -0.0476428037934795, 0.0128147626240249, 
> -0.00215966728793759, 0.163937939472802, -0.0177981879800448, 
> -0.0194674094202263, 0.00596954822329465, 0.00722538746451562, 
> 0.00823795934445926, -0.0531568910141722, -0.0264750975263794, 
> -0.0568005326806897, -0.0117074476225554, -0.00765641773368131, 
> 0.00840018480907645, 0.0134858356786616, 0.0218520449340787, 
> 0.0174402198992674, -0.00421283228781988, 0.0067023567186908, 
> -0.0218526897113769, -0.0334227060998948, -0.00985769710908357, 
> -0.202804033211645, 0, 0.0434513862922259)
>  
>  
> hist(x,breaks="Scott")
> hist(y,breaks="Scott")
> hist(z,breaks="Scott")
> --------------------------------------------------------
> 
> This is not an offer (or solicitation of an offer) to buy/se...{{dropped}}
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> 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.
>



More information about the R-help mailing list