[R] Histogram
Hello, Although I've done lots of research on histograms, I'm still not able to create one. I'd be glad if someone could explain them to me. That's what it eventually should look like: http://www.nabble.com/file/p12423193/histogram.gif The interval limits are: (0), 1, 2, 3, 3.5, 4.5, 5, 5.5, (6) The interval widths are therefore: (1), 1, 1, 0.5, 1, 0.5, 0.5, (0.5) The surface areas are: (0), 0.2, 0.3, 0.3, 0.1, 0, 0.1, (0) I think the argument for the interval limits is breaks, isn't it? How can I define the interval widths? Thanks for any clues Tobias -- View this message in context: http://www.nabble.com/Histogram-tf4359093.html#a12423193 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Histogram
On 8/31/07, squall44 [EMAIL PROTECTED] wrote: Hello, Although I've done lots of research on histograms, I'm still not able to create one. I'd be glad if someone could explain them to me. That's what it eventually should look like: http://www.nabble.com/file/p12423193/histogram.gif The interval limits are: (0), 1, 2, 3, 3.5, 4.5, 5, 5.5, (6) The interval widths are therefore: (1), 1, 1, 0.5, 1, 0.5, 0.5, (0.5) The surface areas are: (0), 0.2, 0.3, 0.3, 0.1, 0, 0.1, (0) I think the argument for the interval limits is breaks, isn't it? How can I define the interval widths? Thanks for any clues Tobias -- You want to do a barplot, as is explained in ?hist. int.width-c(1,1,1,0.5,1,0.5,0.5,0.5) surf.area-c(0,0.2,0.3,0.3,0.1,0,0.1,0) height-surf.area/int.width barplot(height,int.width) _ /Gustaf -- Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik __ R-help@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.
[R] Histogram Title SizeFont
Hello, I would like to plot a histogram with title Return, and I would like the font for the title to be Bold and the size to be 8( as in Excel). I tried the following code, but it does not make any change. Could anyone give me some advice? hist (preturn, seq(-0.05,0.05,0.005),freq = FALSE, main=Return, font=2, cex=8,xlab=return,xlim=c(-0.05,0.05)) Many thanks. -- View this message in context: http://www.nabble.com/Histogram-Title-Size-Font-tf4347319.html#a12385630 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Histogram Title SizeFont
livia wrote: Hello, I would like to plot a histogram with title Return, and I would like the font for the title to be Bold and the size to be 8( as in Excel). I tried the following code, but it does not make any change. Could anyone give me some advice? See ?par. Uwe Ligges hist (preturn, seq(-0.05,0.05,0.005),freq = FALSE, main=Return, font=2, cex=8,xlab=return,xlim=c(-0.05,0.05)) Many thanks. __ R-help@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.
[R] Histogram
Hello, I wanted to create a histogram, but somehow I got stuck... The interval limits are: x = 1, 2, 3, 3.5, 4.5, 5, 5.5 The interval widths are therefore: 1, 1, 0.5, 1, 0.5, 0.5 Nothing I tried worked... Can anyone help me please? Thanks Tobias -- View this message in context: http://www.nabble.com/Histogram-tf4315900.html#a12288850 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Histogram
squall44 wrote: Hello, I wanted to create a histogram, but somehow I got stuck... The interval limits are: x = 1, 2, 3, 3.5, 4.5, 5, 5.5 The interval widths are therefore: 1, 1, 0.5, 1, 0.5, 0.5 Please read the help page more carefully! See ?hist and its argument breaks. Uwe Ligges Nothing I tried worked... Can anyone help me please? Thanks Tobias __ R-help@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.
Re: [R] Histogram
Well, that was the first thing I tried. But the help only gives you the commands and does not explain how to use it (I am a newbe). How do I use the argument 'breaks'? I tried: #--- x = c(1, 2, 3, 3.5, 4.5, 5, 5.5) breaks=c(1, 1, 0.5, 1, 0.5, 0.5) hist(x, breaks= breaks, xlim=c(0,7), ylim=c(0,5)) #--- ...which didn't work. I tried many other variations, but I am a beginner. If anyone can give me a clue, I'd be very thankful. Tobias Uwe Ligges wrote: squall44 wrote: Hello, I wanted to create a histogram, but somehow I got stuck... The interval limits are: x = 1, 2, 3, 3.5, 4.5, 5, 5.5 The interval widths are therefore: 1, 1, 0.5, 1, 0.5, 0.5 Please read the help page more carefully! See ?hist and its argument breaks. Uwe Ligges Nothing I tried worked... Can anyone help me please? Thanks Tobias __ R-help@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. -- View this message in context: http://www.nabble.com/Histogram-tf4315900.html#a12289680 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Histogram
squall44 wrote: Well, that was the first thing I tried. But the help only gives you the commands and does not explain how to use it (I am a newbe). How do I use the argument 'breaks'? I tried: #--- x = c(1, 2, 3, 3.5, 4.5, 5, 5.5) breaks=c(1, 1, 0.5, 1, 0.5, 0.5) hist(x, breaks= breaks, xlim=c(0,7), ylim=c(0,5)) #--- ...which didn't work. Well, breaks means breaks, not the widths of the bins, hence hist(youData, breaks = c(1, 2, 3, 3.5, 4.5, 5, 5.5)) is what you want, but that is meaningsless since you have not yet given any data. Uwe Ligges I tried many other variations, but I am a beginner. If anyone can give me a clue, I'd be very thankful. Tobias Uwe Ligges wrote: squall44 wrote: Hello, I wanted to create a histogram, but somehow I got stuck... The interval limits are: x = 1, 2, 3, 3.5, 4.5, 5, 5.5 The interval widths are therefore: 1, 1, 0.5, 1, 0.5, 0.5 Please read the help page more carefully! See ?hist and its argument breaks. Uwe Ligges Nothing I tried worked... Can anyone help me please? Thanks Tobias __ R-help@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. __ R-help@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.
Re: [R] histogram with absolute figures
In the absence of a data set, it may help to read the help file carefully: ?hist Note, in particular, that the argument freq defaults to TRUE if and only if breaks are equidistant (and probability is not specified). Regards, Mark. Sarah Goslee wrote: Well, how about an example of what you are doing, and a description of what the results you get and the results you want are? When I do a histogram, I get frequencies. Sarah On 7/9/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Meanwhile I have recognized, that the breaks-option enforces density as the default. But if I try to force frequencies (freq=TRUE) I get the following feedback: Warning message: the AREAS in the plot are wrong -- rather use freq=FALSE in: plot.histogram(r, freq = freq, col = col, border = border, angle = angle, And the machine hasn't promised too much: the result IS wrong. Yours, Mag. Ferri Leberl Am Freitag, den 06.07.2007, 16:17 -0400 schrieb Sarah Goslee: The default of hist() is counts rather than percentages. Sarah On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Dear everybody! Is ist easily possible to make up a histogram with absolute numbers instead of percentages? Thank you in advance! Yours, Mag. Ferri Leberl ___ -- Sarah Goslee http://www.functionaldiversity.org __ R-help@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. -- View this message in context: http://www.nabble.com/histogram-with-absolute-figures-tf4037852.html#a11517345 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] histogram with absolute figures
Meanwhile I have recognized, that the breaks-option enforces density as the default. But if I try to force frequencies (freq=TRUE) I get the following feedback: Warning message: the AREAS in the plot are wrong -- rather use freq=FALSE in: plot.histogram(r, freq = freq, col = col, border = border, angle = angle, And the machine hasn't promised too much: the result IS wrong. Yours, Mag. Ferri Leberl Am Freitag, den 06.07.2007, 16:17 -0400 schrieb Sarah Goslee: The default of hist() is counts rather than percentages. Sarah On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Dear everybody! Is ist easily possible to make up a histogram with absolute numbers instead of percentages? Thank you in advance! Yours, Mag. Ferri Leberl ___ __ R-help@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.
Re: [R] histogram with absolute figures
Well, how about an example of what you are doing, and a description of what the results you get and the results you want are? When I do a histogram, I get frequencies. Sarah On 7/9/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Meanwhile I have recognized, that the breaks-option enforces density as the default. But if I try to force frequencies (freq=TRUE) I get the following feedback: Warning message: the AREAS in the plot are wrong -- rather use freq=FALSE in: plot.histogram(r, freq = freq, col = col, border = border, angle = angle, And the machine hasn't promised too much: the result IS wrong. Yours, Mag. Ferri Leberl Am Freitag, den 06.07.2007, 16:17 -0400 schrieb Sarah Goslee: The default of hist() is counts rather than percentages. Sarah On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Dear everybody! Is ist easily possible to make up a histogram with absolute numbers instead of percentages? Thank you in advance! Yours, Mag. Ferri Leberl ___ -- Sarah Goslee http://www.functionaldiversity.org __ R-help@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.
[R] histogram with absolute figures
Dear everybody! Is ist easily possible to make up a histogram with absolute numbers instead of percentages? Thank you in advance! Yours, Mag. Ferri Leberl __ R-help@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.
Re: [R] histogram with absolute figures
The default of hist() is counts rather than percentages. Sarah On 7/6/07, Mag. Ferri Leberl [EMAIL PROTECTED] wrote: Dear everybody! Is ist easily possible to make up a histogram with absolute numbers instead of percentages? Thank you in advance! Yours, Mag. Ferri Leberl ___ -- Sarah Goslee http://www.functionaldiversity.org __ R-help@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.
[R] Histogram
Hello, I am using the following codes to plot a histogram and density line for x. For the density line, I just want it to show the two tails, eg, for x larger than 0.05 ans smaller than -0.05 hist (x, seq(-0.1,0.1,0.01),freq = FALSE) lines (density(x,bw=SJ), x 0.05 x (-0.05), col = red) But is does not work, can anyone give me some advice? -- View this message in context: http://www.nabble.com/Histogram-tf3947281.html#a11197644 Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Histogram
I expect there's a more elegant way of doing this, but this should work: set.seed(101) x - rnorm(500,sd=.03) hist (x, seq(-0.1,0.1,0.01),freq = FALSE) d - density(x,bw=SJ) lowt - d$x -.05 upt - d$x .05 lines (d$x[lowt],d$y[lowt], col = red) lines(d$x[upt],d$y[upt], col = red) On 19/06/07, livia [EMAIL PROTECTED] wrote: Hello, I am using the following codes to plot a histogram and density line for x. For the density line, I just want it to show the two tails, eg, for x larger than 0.05 ans smaller than -0.05 hist (x, seq(-0.1,0.1,0.01),freq = FALSE) lines (density(x,bw=SJ), x 0.05 x (-0.05), col = red) But is does not work, can anyone give me some advice? -- View this message in context: http://www.nabble.com/Histogram-tf3947281.html#a11197644 Sent from the R help mailing list archive at Nabble.com. __ R-help@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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP __ R-help@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.
Re: [R] Histogram
Your subsetting expression in lines does not make any sense at all. Not tested but maybe something like: lines (density(subset(x, x 0.05 x -0.05)bw=SJ), col='red) --- livia [EMAIL PROTECTED] wrote: Hello, I am using the following codes to plot a histogram and density line for x. For the density line, I just want it to show the two tails, eg, for x larger than 0.05 ans smaller than -0.05 hist (x, seq(-0.1,0.1,0.01),freq = FALSE) lines (density(x,bw=SJ), x 0.05 x (-0.05), col = red) But is does not work, can anyone give me some advice? -- View this message in context: http://www.nabble.com/Histogram-tf3947281.html#a11197644 Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.
[R] Histogram using frequency data
Hello, I wanted to know how to plot a histogram using a vector of frequencies rather than the data vector as a whole. So I have two vectors: a vector of labels V1= c(A,B,C,D) and vector B which is a vector of frequencies of A, B, C and D respectively V2=c(20,50,60,30). I wanted to plot a histogram of the labels using the frequencies. I could not figure out a way to do this using the 'hist' function which takes only the full data vector as input. Could you please help me with this? Thank you, Suman [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Histogram using frequency data
On Mon, 2007-06-18 at 19:40 -0400, suman Duvvuru wrote: Hello, I wanted to know how to plot a histogram using a vector of frequencies rather than the data vector as a whole. So I have two vectors: a vector of labels V1= c(A,B,C,D) and vector B which is a vector of frequencies of A, B, C and D respectively V2=c(20,50,60,30). I wanted to plot a histogram of the labels using the frequencies. I could not figure out a way to do this using the 'hist' function which takes only the full data vector as input. Could you please help me with this? Thank you, Suman See ?barplot To wit: V1 - c(A, B, C, D) V2 - c(20, 50, 60, 30) # Do the barplot, saving the bar midpoints in 'mp' mp - barplot(V2, names.arg = V1, ylim = c(0, 80)) # Now add the bar values above the bars text(mp, V2, V2, pos = 3) See ?text and ?mtext for adding annotation HTH, Marc Schwartz __ R-help@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.
[R] Histogram with uneven bins
Hi R-helpers I would like to produce a histogram with uneven bins (e.g., 0, 1-2, 3-5, 6-10, 10-20, 20) but I would like the resulting bars to be the same width ( i.e., a bar's width would not be proportional to its corresponding bin size). Also, the x and y axes of my histograms frequently (almost always, actually) extend beyond the axis labels (i.e., there are unlabeled bars). I would like to label each bar exactly with the range of values that corresponds to it ( i.e., print a 0 underneath the 0 bin, print 1-2) underneath the 1-2 bin, etc. I'd appreciate any help you might be able to provide, thanks! Mark [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Histogram with uneven bins
will this work for you? x - runif(1000, 0, 40) x.c - cut(x, breaks=c(0, 1, 3, 6, 10, Inf)) barplot(table(x.c)) On 4/19/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi R-helpers I would like to produce a histogram with uneven bins (e.g., 0, 1-2, 3-5, 6-10, 10-20, 20) but I would like the resulting bars to be the same width ( i.e., a bar's width would not be proportional to its corresponding bin size). Also, the x and y axes of my histograms frequently (almost always, actually) extend beyond the axis labels (i.e., there are unlabeled bars). I would like to label each bar exactly with the range of values that corresponds to it ( i.e., print a 0 underneath the 0 bin, print 1-2) underneath the 1-2 bin, etc. I'd appreciate any help you might be able to provide, thanks! Mark [[alternative HTML version deleted]] __ R-help@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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@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.
[R] Histogram of ones.
Dear expeRts, I'd like to picture histogram of ones. For example, hist(rep(1, 100), col=lightblue, border=black) A bin is pictured ranging on [0,1] and range of x axis is also [0,1]. How can I adjust the bin range from [0,1] to [0.9, 1] ? I am looking forward to hearing from expeRt. Sincerely, [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Histogram of ones.
If I correctly understand, hist(rep(1, 100), col=lightblue, border=black,breaks=0:10*0.1) see: breaks arg in ?hist On 2/7/07, Dong H. Oh [EMAIL PROTECTED] wrote: Dear expeRts, I'd like to picture histogram of ones. For example, hist(rep(1, 100), col=lightblue, border=black) A bin is pictured ranging on [0,1] and range of x axis is also [0,1]. How can I adjust the bin range from [0,1] to [0.9, 1] ? I am looking forward to hearing from expeRt. Sincerely, [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] histogram bin width
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.018607163516, 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.27744216866, -0.00307369805856439, -0.0418170289885111, -0.00356492258806185, 0.0227847721326668, 0.0401574349545797, -0.0886738669484188, -0.0098704333226, 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.98630164910, 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,
Re: [R] histogram bin width
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.018607163516, 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.27744216866, -0.00307369805856439, -0.0418170289885111, -0.00356492258806185, 0.0227847721326668, 0.0401574349545797, -0.0886738669484188, -0.0098704333226, 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.98630164910, 0.0178528236729925, 0.0413402809899210, 0.116349808290739, 0.0512011287258751, -0.0218604390330945, 0.0153390225896111, 0.0464780076971039, -0.00214304848649149,
[R] Histogram
Dear all, I want to design a histogram and I need to have the frequency at certain points. For example I have the following 2 columns: *X Y* 0.125 0.422 0.45 11 0.55 21 I want the chart to have 4 columns. First column is from 0.0-0.1 (on X) and frequency is 25. Next colum is wider and form 0.1-0.4 with 22 frequency. Next column is narrow with 11 frequency and the last column is the same as the first one with 21 frequency. Can anybody tell me how I can have this chart. Thanks, Mohsen [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Histogram
Hi, There may be an easier way but here is one way you can do it. # create vector that has Y[i] X[i]s new.data - rep(X,Y) hist(new.data, breaks=c(0,.1,.4,.6)) # or something like that look at what exactly breaks should be. Ritwik. On 9/27/06, Mohsen Jafarikia [EMAIL PROTECTED] wrote: Dear all, I want to design a histogram and I need to have the frequency at certain points. For example I have the following 2 columns: *X Y* 0.125 0.422 0.45 11 0.55 21 I want the chart to have 4 columns. First column is from 0.0-0.1 (on X) and frequency is 25. Next colum is wider and form 0.1-0.4 with 22 frequency. Next column is narrow with 11 frequency and the last column is the same as the first one with 21 frequency. Can anybody tell me how I can have this chart. Thanks, Mohsen [[alternative HTML version deleted]] __ R-help@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. -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University [EMAIL PROTECTED] | +12163682366 | http://darwin.cwru.edu/~rsinha __ R-help@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.
Re: [R] Histogram
On Wed, 2006-09-27 at 18:29 -0400, Mohsen Jafarikia wrote: Dear all, I want to design a histogram and I need to have the frequency at certain points. For example I have the following 2 columns: *X Y* 0.125 0.422 0.45 11 0.55 21 I want the chart to have 4 columns. First column is from 0.0-0.1 (on X) and frequency is 25. Next colum is wider and form 0.1-0.4 with 22 frequency. Next column is narrow with 11 frequency and the last column is the same as the first one with 21 frequency. Can anybody tell me how I can have this chart. Thanks, Mohsen How about this: X - c(0, 0.1, 0.4, 0.45, 0.55) Y - c(25, 22, 11, 21) barplot(Y, space = 0, width = diff(X)) axis(1) See ?barplot and ?diff HTH, Marc Schwartz __ R-help@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.
[R] histogram colors in lattice
I have code that constructs a plot using the lattice package that looks something like the following toy example: library(lattice) Start - factor(rbinom(100,1,.5)) Answer - 2 - rbinom(100,1,.7) histogram(~Answer | Start, breaks=c(1, 1.4 ,1.6,2), scales=list(x=list(at=c(1.2,1.8),labels=c(Yes,No))), xlab=,ylab=) I would like to have different colors for the bars in the left and right panel (say red and green) but I can't find a way to do this. Can anyone give me any advice on how to achieve this? Thanks, Jamie Jarabek [[alternative HTML version deleted]] __ R-help@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.
Re: [R] histogram colors in lattice
Try this: library(lattice) set.seed(1) ## added for reproducibility Start - factor(rbinom(100,1,.5)) Answer - 2 - rbinom(100,1,.7) histogram(~Answer | Start, breaks=c(1, 1.4 ,1.6,2), scales=list(x=list(at=c(1.2,1.8),labels=c(Yes,No))), panel = function(x, ..., panel.number, col) { ## added this panel function panel.histogram(x, ..., col = panel.number+1) }, xlab=,ylab=) On 9/26/06, Jamie Jarabek [EMAIL PROTECTED] wrote: I have code that constructs a plot using the lattice package that looks something like the following toy example: library(lattice) Start - factor(rbinom(100,1,.5)) Answer - 2 - rbinom(100,1,.7) histogram(~Answer | Start, breaks=c(1, 1.4 ,1.6,2), scales=list(x=list(at=c(1.2,1.8),labels=c(Yes,No))), xlab=,ylab=) I would like to have different colors for the bars in the left and right panel (say red and green) but I can't find a way to do this. Can anyone give me any advice on how to achieve this? Thanks, Jamie Jarabek [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] histogram frequency weighing
Fellow R-helpers, Suppose we create a histogram as follows (although it could be any vector with zeroes in it): R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R lenh$counts [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 [26] 1 0 6 0 7 0 6 0 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 [51] 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 0 1 0 0 0 1 0 4 0 [76] 0 0 1 0 0 and we wanted to apply a weighing scheme where frequencies immediately following (and only those) empty class intervals (0) should be adjusted by averaging them over the number of preceding empty intervals + 1. For example, the first frequency that would need to be adjusted in 'lenh' is element 6 (1), which has 5 preceding empty intervals, so its adjusted count would be 1/6. Similarly, the second one would be element 8 (3), which has 1 preceding empty interval, so its adjusted count would be 3/2. Can somebody please provide a hint to implement such a weighing scheme? I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I couldn't find relevant info in the usual channels. Thanks in advance for any pointers. Cheers, -- Seb __ R-help@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.
Re: [R] histogram frequency weighing
I think this should do it: lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05))$counts lenh # original data [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 1 0 6 0 7 0 6 0 [34] 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 [67] 0 1 0 0 0 1 0 4 0 0 0 1 0 0 l.rle - rle(lenh) # determine where '0's are Zero - which(l.rle$values == 0) # if last entry in rle was 0, delete from offsets since we are changing +1 if (tail(l.rle$values,1) == 0) Zero - Zero[-length(Zero)] l.offsets - cumsum(l.rle$lengths) # offsets into original vector# modify original input lenh[l.offsets[Zero+1]] - lenh[l.offsets[Zero + 1]] / (l.rle$lengths[Zero]+1) lenh # modified data [1] 0.000 0.000 0.000 0.000 0.000 0.167 0.000 1.500 0.000 0.500 [11] 0.000 2.000 0.000 1.000 0.000 2.500 0.000 3.000 0.000 5.000 [21] 0.000 4.500 0.000 2.000 0.000 0.500 0.000 3.000 0.000 3.500 [31] 0.000 3.000 0.000 4.000 0.000 3.500 0.000 1.500 0.000 3.000 [41] 0.000 3.000 0.000 2.000 0.000 4.500 0.000 3.500 0.000 2.500 [51] 0.000 1.000 0.000 4.000 0.000 1.500 0.000 2.000 0.000 0.500 [61] 0.000 0.500 0.000 1.500 0.000 0.500 0.000 0.500 0.000 0.000 [71] 0.000 0.250 0.000 2.000 0.000 0.000 0.000 0.250 0.000 0.000 On 9/17/06, Sebastian P. Luque [EMAIL PROTECTED] wrote: Fellow R-helpers, Suppose we create a histogram as follows (although it could be any vector with zeroes in it): R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R lenh$counts [1] 0 0 0 0 0 1 0 3 0 1 0 4 0 2 0 5 0 6 0 10 0 9 0 4 0 [26] 1 0 6 0 7 0 6 0 8 0 7 0 3 0 6 0 6 0 4 0 9 0 7 0 5 [51] 0 2 0 8 0 3 0 4 0 1 0 1 0 3 0 1 0 1 0 0 0 1 0 4 0 [76] 0 0 1 0 0 and we wanted to apply a weighing scheme where frequencies immediately following (and only those) empty class intervals (0) should be adjusted by averaging them over the number of preceding empty intervals + 1. For example, the first frequency that would need to be adjusted in 'lenh' is element 6 (1), which has 5 preceding empty intervals, so its adjusted count would be 1/6. Similarly, the second one would be element 8 (3), which has 1 preceding empty interval, so its adjusted count would be 3/2. Can somebody please provide a hint to implement such a weighing scheme? I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I couldn't find relevant info in the usual channels. Thanks in advance for any pointers. Cheers, -- Seb __ R-help@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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@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.
Re: [R] histogram frequency weighing
On Sun, 17 Sep 2006 15:12:30 -0500, Sebastian P. Luque [EMAIL PROTECTED] wrote: [...] I thought about some very contrived ways to accomplish this, involving 'which' and 'diff', but I sense a function might already be available to do this efficiently. I think I found a better combination of those two functions than I what I was initially playing with: R lenh - hist(iris$Sepal.Length, br=seq(4, 8, 0.05)) R ok - which(lenh$counts 0) R lenh$counts[ok] - lenh$counts[ok] / diff(c(0, ok)) R lenh$counts [1] 0. 0. 0. 0. 0. 0.1667 0. 1.5000 0. 0.5000 [11] 0. 2. 0. 1. 0. 2.5000 0. 3. 0. 5. [21] 0. 4.5000 0. 2. 0. 0.5000 0. 3. 0. 3.5000 [31] 0. 3. 0. 4. 0. 3.5000 0. 1.5000 0. 3. [41] 0. 3. 0. 2. 0. 4.5000 0. 3.5000 0. 2.5000 [51] 0. 1. 0. 4. 0. 1.5000 0. 2. 0. 0.5000 [61] 0. 0.5000 0. 1.5000 0. 0.5000 0. 0.5000 0. 0. [71] 0. 0.2500 0. 2. 0. 0. 0. 0.2500 0. 0. It makes sense, although I'm a bit nervous about floating-point issues that might make this fail in some cases. Any suggestions/comments welcome. -- Seb __ R-help@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.
Re: [R] histogram frequency weighing
On Sun, 17 Sep 2006 18:05:15 -0400, jim holtman [EMAIL PROTECTED] wrote: I think this should do it: [...] Thank you Jim, the idea with 'rle' is great. I missed your follow-up before mine a minute ago with another solution. I'll do some testing with both. Cheers, -- Seb __ R-help@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.
[R] Histogram of data with categorical varialbe
Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Histogram of data with categorical varialbe
Alexandre Depire wrote: Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf Something like : d - data.frame( x = rnorm(100), sex = sample(c(1,2), replace=TRUE, size=100)) out - hist(d$x, col=gray) hist(d$x[d$sex==2], col=red, add=T, breaks=out$breaks) legend(topleft, c(male,female) , fill=c(gray,red)) box() Cheers, Romain -- *mangosolutions* /data analysis that delivers/ Tel +44 1249 467 467 Fax +44 1249 467 468 __ R-help@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.
Re: [R] Histogram of data with categorical varialbe
On Fri, 15 Sep 2006 16:45:31 +0200 Alexandre Depire wrote: Hello, I have the following data: Km Sex 250 1 300 2 290 2 600 1 450 2 650 1 . I would like to obtain one histogram where the data (or the part) of each sex is visible, it is like cumulative histogram or spinogram. To be more comprehensible, i would like to know if the following graph is obtainable easily in R. It is the first graph on page 5 in the following document http://jasp.ism.ac.jp/~nakanoj/workshop04/TalkII.pdf I think it's not available out of the box, but you can easily generate this yourself. Using the space shuttle o-ring data as an example (see also ?spineplot): fail - factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1), levels = c(1, 2), labels = c(no, yes)) temperature - c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70, 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81) The you can do the following: ## generate unconditional histogram of numeric variable P(x) col - gray.colors(2) ht - hist(temperature, freq = FALSE, col = col[2]) ## using the same breaks, compute the conditional histogram P(x|group) br - ht$breaks ht2 - hist(temperature[fail == yes], plot = FALSE, freq = FALSE, breaks = br) ## and then add the rectangles using the joint densities ## P(x group) = P(x|group) * P(group) rect(br[-length(br)], 0, br[-1], ht2$density * mean(fail == yes), col = col[1]) Furthermore, you can take a look at the iplots package which should provide an interactive approach to this. Z [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] histogram in the background?
I intend to draw a plot of y against x. In the background of this graph I wish to creat a histogram of the horizontal variable x. Does any expert know how to produce such a plot? [[alternative HTML version deleted]] __ R-help@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.
Re: [R] histogram in the background?
How about this? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 JeeBee On Wed, 06 Sep 2006 18:19:28 +0800, gallon li wrote: I intend to draw a plot of y against x. In the background of this graph I wish to creat a histogram of the horizontal variable x. Does any expert know how to produce such a plot? [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
Re: [R] histogram in the background?
gallon li wrote: I have found this one before. However, my intension is slightly differing from this plot: I wish to plot the histogram in the backgroun instead of in the margin. Thanks anyway! On Wed, 06 Sep 2006 12:29:51 +0200, JeeBee wrote: How about this? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 JeeBee __ R-help@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.
Re: [R] histogram in the background?
--- JeeBee [EMAIL PROTECTED] wrote: gallon li wrote: I have found this one before. However, my intension is slightly differing from this plot: I wish to plot the histogram in the backgroun instead of in the margin. Thanks anyway! On Wed, 06 Sep 2006 12:29:51 +0200, JeeBee wrote: How about this? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 JeeBee Can you not just plot the histogram and then the main plot? Something like this, although it is a barplot rather than a histogram. Hours - c(0,1,2,3,4,5) Nam - c( alf, bet, cet, det, NA , fet) En - c(5, 7, 8, 9, NA, 9) L1 - c(10, 9, 7, 5, 3 ,6) L2 - c(7, 4, 3, 2, 5, 7) MyLabels - seq(200, 500, length=13) mp -barplot(En) # adjust margins to accommodate titles and labels especially the 4 axis label. par(mar=c(5,5,5,5)) barplot(En, ylim=c(0, 12),axes =FALSE, ann=FALSE, xlab=Hours, ylab=Volume, col.lab=blue) points (mp,L1, type=p, pch=19, col = red) points (mp,L2, type = l, col=blue) axis ( 2, 0:12, las=1, font=2) axis (3, at=1:6, tick =F, labels =c( alf, bet, cet, det, NA , fet)) axis (4, at = 0:12, labels = MyLabels, font=2) mtext(Number of Units Detected, 4, line=3,col=blue) title ( main=A combined line and bar chart \n with different x-axis labels, line=3, font=3, col.main=blue) box() __ R-help@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.
Re: [R] histogram in the background?
I intend to draw a plot of y against x. In the background of this graph I wish to creat a histogram of the horizontal variable x. Does any expert know how to produce such a plot? When constructing such a plot, you need to be careful that you don't end up constructing a pretty picture instead of a statistical graphic. In this case you need to ask yourself, what would the y-axis represent? What scale would it have? Hadley __ R-help@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.
[R] histogram breaks as labels
Hi all, I would like to know if there is a way to have the diplay the breaks of the hist (as myhist$breaks here in the example) as the labels, instead of the myhist$counts: input = rpois(1000,5) myhist = hist(input, breaks = 15, labels=TRUE, axes=FALSE) So that, instead of having: 94 140 187 181 145 117 68 42 15 5 1 5 on top of the columns, I have: 1 2 3 4 5 6 7 8 9 10 11 12 13 as in myhist$breaks. Thanks in advance, Albert. __ R-help@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
Re: [R] histogram breaks as labels
try something along these lines: input - rpois(1000, 5) myhist - hist(input, breaks = 15, plot = FALSE) plot(myhist, labels = as.character(myhist$breaks[-1]), axes = FALSE) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Albert Vilella [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Monday, May 08, 2006 2:01 PM Subject: [R] histogram breaks as labels Hi all, I would like to know if there is a way to have the diplay the breaks of the hist (as myhist$breaks here in the example) as the labels, instead of the myhist$counts: input = rpois(1000,5) myhist = hist(input, breaks = 15, labels=TRUE, axes=FALSE) So that, instead of having: 94 140 187 181 145 117 68 42 15 5 1 5 on top of the columns, I have: 1 2 3 4 5 6 7 8 9 10 11 12 13 as in myhist$breaks. Thanks in advance, Albert. __ R-help@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 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@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
Re: [R] histogram breaks as labels
On Mon, 2006-05-08 at 14:22 +0200, Dimitris Rizopoulos wrote: try something along these lines: input - rpois(1000, 5) myhist - hist(input, breaks = 15, plot = FALSE) plot(myhist, labels = as.character(myhist$breaks[-1]), axes = FALSE) it seems to give me the labels slided by one, but it seems to works with: plot(myhist, labels = as.character(myhist$breaks[-length(myhist $breaks)]), axes = FALSE) at least for the example I'm using, Thanks Dimitris, Albert. I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://www.med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Albert Vilella [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Monday, May 08, 2006 2:01 PM Subject: [R] histogram breaks as labels Hi all, I would like to know if there is a way to have the diplay the breaks of the hist (as myhist$breaks here in the example) as the labels, instead of the myhist$counts: input = rpois(1000,5) myhist = hist(input, breaks = 15, labels=TRUE, axes=FALSE) So that, instead of having: 94 140 187 181 145 117 68 42 15 5 1 5 on top of the columns, I have: 1 2 3 4 5 6 7 8 9 10 11 12 13 as in myhist$breaks. Thanks in advance, Albert. __ R-help@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 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@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
[R] Histogram to compare two datasets
Dear All, I am trying to create a histogram-like plot for comparing two datasets - For each interval, I want it to draw 2 bars - one for representing the number of values in each dataset for that interval. I have looked at the help for the hist() function and also for the histogram() function that is part of the lattice package, and neither seem to support multiple datasets. Could someone please point me in the right direction? Kind regards, Johan van Niekerk __ R-help@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
Re: [R] Histogram to compare two datasets
Le 21.04.2006 10:48, Johan van Niekerk a écrit : Dear All, I am trying to create a histogram-like plot for comparing two datasets - For each interval, I want it to draw 2 bars - one for representing the number of values in each dataset for that interval. I have looked at the help for the hist() function and also for the histogram() function that is part of the lattice package, and neither seem to support multiple datasets. Could someone please point me in the right direction? Kind regards, Johan van Niekerk Look there : http://addictedtor.free.fr/graphiques/search.php?q=histogram -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques mixmod 1.7 is released : http://www-math.univ-fcomte.fr/mixmod/index.php +---+ | Romain FRANCOIS - http://francoisromain.free.fr | | Doctorant INRIA Futurs / EDF | +---+ __ R-help@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
[R] histogram error: 'x' must be numeric
Hi All, I have problem to plot histogram. What I did is: export a .csv file from PSQL database's table. so, inside this .csv file it looks like: 31.845 24.598 29.1223 24.715 23.1847 24.2321 25.2995 23.4261 30.7873 .. Then, I use command: score- read.csv('file.csv', header = FALSE,sep = ,) hist(score, main = score) it gives error msg: Error in hist.default(score, main = score) : 'x' must be numeric Can any of you know about it explain me why? Thanks a lot. Nina [[alternative HTML version deleted]] __ R-help@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
Re: [R] histogram error: 'x' must be numeric
jia ding wrote: Then, I use command: score- read.csv('file.csv', header = FALSE,sep = ,) hist(score, main = score) it gives error msg: Error in hist.default(score, main = score) : 'x' must be numeric Can any of you know about it explain me why? Have a look at 'score' in R first. You might get this: score V1 1 31.8450 2 24.5980 3 29.1223 4 24.7150 5 23.1847 6 24.2321 7 25.2995 8 23.4261 9 30.7873 - read.csv reads things in into data frames - a bit like a matrix. You've read your data into a data frame with one column, so you can do: hist(score$V1) since V1 is the name of the column. If your data is just one column, then you could do: score = scan(file.csv) and then hist(score) since scan() has read it into a single vector, not a data frame. Barry __ R-help@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
Re: [R] Histogram over a Large Data Set (DB): How?
Sean == Sean Davis [EMAIL PROTECTED] writes: Sean Have you tried just grabbing the whole column using dbGetQuery? Sean Try doing this: Sean Sean spams - dbGetQuery(con,select unixtime from email limit Sean 100) Sean Sean Then increase from 1,000,000 to 1.5 million, to 2 million, etc. Sean until you break something (run out of memory), if you do at all. Yes, you are right. For the example problem that I posed, R can indeed process the entire query result in memory. (The R process grows to 240MB, though!) Sean However, the BETTER way to do this, if you already have the data Sean in the database is to allow the database to do the histogram for Sean you. For example, to get a count of spams by day, in MySQL do Sean something like: [...] Yes, again you are right --- the particular problem that I posed is probably better handled by formulating a more sophisticated SQL query. But really, my goal isn't to solve the the example problem that I posed --- rather, it is to understand how people use R to process very large data sets. The research project that I'm working on will eventually need to deal with query results that cannot fit in main memory, and for which the built-in statistical facilities of most DBMSs will be insufficient. Some of my colleagues have previously written their analyses by hand, using various scripting languages to read and process records from a DB in chunks. Writing things in this way, however, can be tedious and error-prone. Instead of taking this approach, I would like to be able to use existing statistics packages that have the ability to deal with large datasets in good ways. So, I seek to understand the ways that people deal with these sorts of situations in R. Your advice is very helpful --- one should solve problems in the simplest ways available! --- but I would still like to understand the harder cases, and how one can use general R functions in combination with DBI's `dbApply' and `fetch' interfaces, which divide results into chunks. Thanks! Eric. -- --- Eric Eide [EMAIL PROTECTED] . University of Utah School of Computing http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX __ R-help@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
Re: [R] Histogram over a Large Data Set (DB): How?
Eric Eide wrote: Sean == Sean Davis [EMAIL PROTECTED] writes: Sean Have you tried just grabbing the whole column using dbGetQuery? Sean Try doing this: Sean Sean spams - dbGetQuery(con,select unixtime from email limit Sean 100) Sean Sean Then increase from 1,000,000 to 1.5 million, to 2 million, etc. Sean until you break something (run out of memory), if you do at all. Yes, you are right. For the example problem that I posed, R can indeed process the entire query result in memory. (The R process grows to 240MB, though!) Sean However, the BETTER way to do this, if you already have the data Sean in the database is to allow the database to do the histogram for Sean you. For example, to get a count of spams by day, in MySQL do Sean something like: [...] Yes, again you are right --- the particular problem that I posed is probably better handled by formulating a more sophisticated SQL query. But really, my goal isn't to solve the the example problem that I posed --- rather, it is to understand how people use R to process very large data sets. The research project that I'm working on will eventually need to deal with query results that cannot fit in main memory, and for which the built-in statistical facilities of most DBMSs will be insufficient. Some of my colleagues have previously written their analyses by hand, using various scripting languages to read and process records from a DB in chunks. Writing things in this way, however, can be tedious and error-prone. Instead of taking this approach, I would like to be able to use existing statistics packages that have the ability to deal with large datasets in good ways. So, I seek to understand the ways that people deal with these sorts of situations in R. Your advice is very helpful --- one should solve problems in the simplest ways available! --- but I would still like to understand the harder cases, and how one can use general R functions in combination with DBI's `dbApply' and `fetch' interfaces, which divide results into chunks. You might be interested in our project: NetEpi Analysis, which aims to provide interactive exploratory data analysis and basic epidemiological analysis via both a Web front end and a Python programmatic API (forgive the redundancy in programmatic API) for datests up to around 30 million rows (and as many columns as you like) on 32 bit platforms - hundreds of millions of rows should be feasible on 64-bit platforms. It stores data column-wise in memory-mapped on-disc arrays, and uses set operations on ordinal indexes to permit rapid subsetting and cross-tabulation of categorical (factored) data. It is written in Python, but uses R for graphics and some (but not all) statistical calculations (and for model fitting when we get round to providing facilities for same). See http://www.netepi.org - still in alpha, with an update coming out by December. Although it is aimed at epidemiological analysis (of large administrative health datasets), I dare say it might be useful for exploring large databases of spam too. Tim C __ R-help@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
[R] Histogram over a Large Data Set (DB): How?
Hi! I'm new to R, and I have a question about how R works with large data sets --- in particular, data sets that come from databases. I'm using R 2.2.0 with the DBI package (0.1-9) and the RMySQL package (0.5-5). My get-my-feet-wet-with-R project is to make a histogram from a data set stored in a MySQL database. In particular, I have a table that describes some observed spam emails. The 'unixtime' column of the table contains the timestamps of the messages. My current goal is to plot the number of spams per day during the recording period. So far, this is my script (edited for brevity), and it works well: - library(RMySQL) drv - dbDriver(MySQL) con - dbConnect(drv, group=spam) # where clause to limit data set size, as described below. spams - dbGetQuery(con, select unixtime from email where LENGTH(email_to)=4) firstspam - min(spams$unixtime) lastspam - max(spams$unixtime) # spansize == one day spansize - 60 * 60 * 24 firstbreak = floor(firstspam / spansize) lastbreak = celing(lastspam / spansize) spambreaks = (firstbreak:lastbreak) * spansize hist(spams$unixtime, br=spambreaks, plot=TRUE, col=red) - The where clause serves to limit the number of records, while I figure out the surrounding parts. And now I'd like to do that... but I'm not sure how! The actual email table has 2.9 million rows (a lot of spam!), so I presume that I cannot (or at least, shouldn't) read it all at once. Reading the documentation of the RMySQL package, I understand that the syntax I want is something like this: - rs - dbSendQuery(con, select unixtime from email order by unixtime) out - dbApply(rs, INDEX = unixtime, FUN = function(x, grp) hist(x$unixtime, ...)) - But I can't quite seem to make this work. When I try the above directly, I get errors like this: Error in mysqlDBApply(res, ...) : unimplemented type 'NULL' in 'length-' More generally, I'm pretty sure that I'm misusing `hist' in the code above. I don't want a series of histograms; I want just one histogram, made from the concatenation of all the records fetched from the table. I didn't find a recipe for doing this sort of thing in the R FAQ or in the archives for this mailing list, so I'm hoping that someone can set me on the right track. How does one code in R with functions that expect whole vectors, and somehow provide those vectors in a piecemeal fashion? Is there a general recipe for this situation in R (aren't large data sets common?), or do I need to code the histogram generator myself? Thanks for any help! --- Eric. -- --- Eric Eide [EMAIL PROTECTED] . University of Utah School of Computing http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX __ R-help@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
Re: [R] Histogram over a Large Data Set (DB): How?
[R] Histogram over a Large Data Set (DB): How? Have you tried just grabbing the whole column using dbGetQuery? Try doing this: spams - dbGetQuery(con,select unixtime from email limit 100) Then increase from 1,000,000 to 1.5 million, to 2 million, etc. until you break something (run out of memory), if you do at all. However, the BETTER way to do this, if you already have the data in the database is to allow the database to do the histogram for you. For example, to get a count of spams by day, in MySQL do something like: spams - dbGetQuery(con,select date_format(unixtime,'%m/%d/%y'),count(*) from email group by date_format(unixtime,'%m/%d/%y')) Then, you will have a count of the number of spams by date and can plot as you like. Sean - Original Message - From: Eric Eide To: r-help@stat.math.ethz.ch Sent: Thursday, November 17, 2005 6:25 PM Subject: [R] Histogram over a Large Data Set (DB): How? Hi! I'm new to R, and I have a question about how R works with large data sets --- in particular, data sets that come from databases. I'm using R 2.2.0 with the DBI package (0.1-9) and the RMySQL package (0.5-5). My get-my-feet-wet-with-R project is to make a histogram from a data set stored in a MySQL database. In particular, I have a table that describes some observed spam emails. The 'unixtime' column of the table contains the timestamps of the messages. My current goal is to plot the number of spams per day during the recording period. So far, this is my script (edited for brevity), and it works well: - library(RMySQL) drv - dbDriver(MySQL) con - dbConnect(drv, group=spam) # where clause to limit data set size, as described below. spams - dbGetQuery(con, select unixtime from email where LENGTH(email_to)=4) firstspam - min(spams$unixtime) lastspam - max(spams$unixtime) # spansize == one day spansize - 60 * 60 * 24 firstbreak = floor(firstspam / spansize) lastbreak = celing(lastspam / spansize) spambreaks = (firstbreak:lastbreak) * spansize hist(spams$unixtime, br=spambreaks, plot=TRUE, col=red) - The where clause serves to limit the number of records, while I figure out the surrounding parts. And now I'd like to do that... but I'm not sure how! The actual email table has 2.9 million rows (a lot of spam!), so I presume that I cannot (or at least, shouldn't) read it all at once. Reading the documentation of the RMySQL package, I understand that the syntax I want is something like this: - rs - dbSendQuery(con, select unixtime from email order by unixtime) out - dbApply(rs, INDEX = unixtime, FUN = function(x, grp) hist(x$unixtime, ...)) - But I can't quite seem to make this work. When I try the above directly, I get errors like this: Error in mysqlDBApply(res, ...) : unimplemented type 'NULL' in 'length-' More generally, I'm pretty sure that I'm misusing `hist' in the code above. I don't want a series of histograms; I want just one histogram, made from the concatenation of all the records fetched from the table. I didn't find a recipe for doing this sort of thing in the R FAQ or in the archives for this mailing list, so I'm hoping that someone can set me on the right track. How does one code in R with functions that expect whole vectors, and somehow provide those vectors in a piecemeal fashion? Is there a general recipe for this situation in R (aren't large data sets common?), or do I need to code the histogram generator myself? Thanks for any help! --- Eric. -- --- Eric Eide [EMAIL PROTECTED] . University of Utah School of Computing http://www.cs.utah.edu/~eeide/ . +1 (801) 585-5512 voice, +1 (801) 581-5843 FAX __ R-help@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 __ R-help@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
[R] Histogram font
The hist() command produces this message on my machine... Error in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) : X11 font at size 14 could not be loaded How can I either (a) determine what font is required, or (b) specify one of the fonts I have available? This problem is specific to hist(), plot() works fine. I am using R on SuSE Linux v9.3, from the KDE desktop. -- Christopher Willmot __ R-help@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
Re: [R] Histogram font
On Wed, 16 Nov 2005, Christopher Willmot wrote: The hist() command produces this message on my machine... Error in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) : X11 font at size 14 could not be loaded How can I either (a) determine what font is required, or (b) specify one of the fonts I have available? This problem is specific to hist(), plot() works fine. I am using R on SuSE Linux v9.3, from the KDE desktop. Try searching the mailing list, this feels like: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/20511.html -- Roger Bivand Economic Geography Section, Department of Economics, Norwegian School of Economics and Business Administration, Helleveien 30, N-5045 Bergen, Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43 e-mail: [EMAIL PROTECTED] __ R-help@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
Re: [R] Histogram font
On Wed, 16 Nov 2005, Christopher Willmot wrote: The hist() command produces this message on my machine... Error in title(main = main, sub = sub, xlab = xlab, ylab = ylab, ...) : X11 font at size 14 could not be loaded How can I either (a) determine what font is required, or (b) specify one of the fonts I have available? ?options (see option X11fonts). This problem is specific to hist(), plot() works fine. I am using R on SuSE Linux v9.3, from the KDE desktop. This usually means that 100dpi fonts are missing or not in the X11 font path. The code assumes that the standard 75dpi and where necessary 100dpi fonts are installed. The issue is title(), not hist() and not plot() as the error message shows. So calling plot(main=) would also fail. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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
[R] histogram - one bin for all values larger than a certain value
Dear all, I wonder if I can put together a histogram where one bin contains all the values that are larger than a certain specified value. Example: I have values ranging from 0 to 40 and I want 10 bins from 0 to 10, i.e. for the intervals [0,1), [1,2) , ..., [9,10). And then I want one last bin which contains all the values larger than 10, i.e. for the interval [10, 40). Thanks, Florian __ R-help@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
Re: [R] histogram - one bin for all values larger than a certain value
Florian Defregger wrote: Dear all, I wonder if I can put together a histogram where one bin contains all the values that are larger than a certain specified value. Example: I have values ranging from 0 to 40 and I want 10 bins from 0 to 10, i.e. for the intervals [0,1), [1,2) , ..., [9,10). And then I want one last bin which contains all the values larger than 10, i.e. for the interval [10, 40). Thanks, Florian Hi, Florian, See the breaks argument in ?hist. x - sample(1:40, 1000, replace = TRUE) hist(x, breaks = c(0:10, 40)) Is this what you intended? --sundar __ R-help@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
Re: [R] histogram - one bin for all values larger than a certain value
Le 26.09.2005 16:15, Sundar Dorai-Raj a écrit : Florian Defregger wrote: Dear all, I wonder if I can put together a histogram where one bin contains all the values that are larger than a certain specified value. Example: I have values ranging from 0 to 40 and I want 10 bins from 0 to 10, i.e. for the intervals [0,1), [1,2) , ..., [9,10). And then I want one last bin which contains all the values larger than 10, i.e. for the interval [10, 40). Thanks, Florian Hi, Florian, See the breaks argument in ?hist. x - sample(1:40, 1000, replace = TRUE) hist(x, breaks = c(0:10, 40)) Is this what you intended? --sundar Maybe also take a look at the right argument. I think this is closer to what Florian wanted in the first place : R hist(x, breaks = c(0:10, 40), right=FALSE) Romain -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@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
Re: [R] histogram - one bin for all values larger than a certain value
x=runif(100,0,40) hist(x, breaks=c(0,1,2,3,4,5,6,7,8,9,10,40)) Is this what you had in mind? Francisco From: Florian Defregger [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject: [R] histogram - one bin for all values larger than a certain value Date: Mon, 26 Sep 2005 15:36:21 +0200 Dear all, I wonder if I can put together a histogram where one bin contains all the values that are larger than a certain specified value. Example: I have values ranging from 0 to 40 and I want 10 bins from 0 to 10, i.e. for the intervals [0,1), [1,2) , ..., [9,10). And then I want one last bin which contains all the values larger than 10, i.e. for the interval [10, 40). Thanks, Florian __ R-help@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 __ R-help@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
Re: [R] histogram method for S4 class.
Deepayan Sarkar wrote: On 8/24/05, ernesto [EMAIL PROTECTED] wrote: Hi, I'm trying to develop an histogram method for a class called FLQuant which is used by the package FLCore (http://flr-project.org). FLQuant is an extension to array. There is an as.data.frame method that coerces flquant into a data.frame suitable for lattice plotting. The problem is that when I coerce the object and plot it after it works but if the method is applied within the histogram method it does not work. See the code below (the FLCore package is here http://prdownloads.sourceforge.net/flr/FLCore_1.0-1.tar.gz?download) library(FLCore) Loading required package: lattice data(ple4) histogram(~data|year, [EMAIL PROTECTED]) Error in inherits(x, factor) : Object x not found histogram(~data|year, data=as.data.frame([EMAIL PROTECTED])) The catch.n slot is a FLQuant object and the code for histogram is the following setMethod(histogram, signature(formula=formula, data=FLQuant), function (formula, data = parent.frame(), allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, aspect = fill, panel = panel.histogram, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, type = c(percent, count, density), nint = if (is.factor(x)) length(levels(x)) else round(log2(length(x)) + 1), endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04), breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + 1) else do.breaks(endpoints, nint), equal.widths = TRUE, drop.unused.levels = lattice.getOption(drop.unused.levels), ..., default.scales = list(), subscripts = !is.null(groups), subset = TRUE) { qdf - as.data.frame(data) histogram(formula, data = qdf, allow.multiple = allow.multiple, outer = outer, auto.key = auto.key, aspect = aspect, panel = panel, prepanel = prepanel, scales = scales, strip = strip, groups = groups, xlab=xlab, xlim=xlim, ylab=ylab, ylim=ylim, type = type, nint = nint, endpoints = endpoints, breaks = breaks, equal.widths = equal.widths, drop.unused.levels = drop.unused.levels, ..., default.scales = default.scales, subscripts = subscripts, subset = subset) } ) Any ideas ? [I'm CC-ing to r-devel, please post follow-ups there] What version of lattice are you using? Please use the latest one, in which histogram is an S3 generic, with only one argument, formula. The eventual solution to your problem may involve changing that, but the first question to ask is whether any other formula makes sense in your context (if not, I would rather keep one argument and dispatch on signature(formula = FLQuant). Disclaimer: I haven't actually had time to check out FLCore yet, I will as soon as I can. Deepayan Hi, I've installed the version that is distributed with R-2.1.1, 0.11-8. I see there's a new version now so I'll install it and check the results. I've developed the code a little more using the approach you use for dotplot (see below) and I know where the problem is now. I'm not able to pass the argument nint, breaks and endpoints to the function call. I guess the problem is my programming skils :-( Thanks EJ ps: I'm not a subscriber of r-devel so I guess I'm not able to post there, anyway I'm CC-ing there too. setMethod(histogram, signature(formula=formula, data=FLQuant), function (formula, data = parent.frame(), allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, aspect = fill, panel = panel.histogram, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, type = c(percent, count, density), nint = if (is.factor(x)) length(levels(x)) else round(log2(length(x)) + 1), endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04), breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + 1) else do.breaks(endpoints, nint), equal.widths = TRUE, drop.unused.levels = lattice.getOption(drop.unused.levels), ..., default.scales = list(), subscripts = !is.null(groups), subset = TRUE) { # need to develop further, at the moment is not possible to control nint, breaks and endpoints. data - as.data.frame(data) dots - list(...) groups - eval(substitute(groups), data, parent.frame()) subset - eval(substitute(subset), data, parent.frame()) call.list - c(list(formula = formula, data = data, groups = groups, subset = subset, allow.multiple = allow.multiple, outer = outer, auto.key = auto.key, aspect = aspect, panel = panel, prepanel = prepanel, scales = scales, strip = strip, type = type, equal.widths = equal.widths, drop.unused.levels = drop.unused.levels, default.scales = default.scales, subscripts = subscripts), dots) # include xlab co if existent if(!missing(xlab)) call.list$xlab - xlab if(!missing(ylab)) call.list$ylab - ylab if(!missing(xlim)) call.list$xlim - xlim if(!missing(ylim))
Re: [R] histogram method for S4 class.
On 8/24/05, ernesto [EMAIL PROTECTED] wrote: Hi, I'm trying to develop an histogram method for a class called FLQuant which is used by the package FLCore (http://flr-project.org). FLQuant is an extension to array. There is an as.data.frame method that coerces flquant into a data.frame suitable for lattice plotting. The problem is that when I coerce the object and plot it after it works but if the method is applied within the histogram method it does not work. See the code below (the FLCore package is here http://prdownloads.sourceforge.net/flr/FLCore_1.0-1.tar.gz?download) library(FLCore) Loading required package: lattice data(ple4) histogram(~data|year, [EMAIL PROTECTED]) Error in inherits(x, factor) : Object x not found histogram(~data|year, data=as.data.frame([EMAIL PROTECTED])) The catch.n slot is a FLQuant object and the code for histogram is the following setMethod(histogram, signature(formula=formula, data=FLQuant), function (formula, data = parent.frame(), allow.multiple = is.null(groups) || outer, outer = FALSE, auto.key = FALSE, aspect = fill, panel = panel.histogram, prepanel = NULL, scales = list(), strip = TRUE, groups = NULL, xlab, xlim, ylab, ylim, type = c(percent, count, density), nint = if (is.factor(x)) length(levels(x)) else round(log2(length(x)) + 1), endpoints = extend.limits(range(x[!is.na(x)]), prop = 0.04), breaks = if (is.factor(x)) seq(0.5, length = length(levels(x)) + 1) else do.breaks(endpoints, nint), equal.widths = TRUE, drop.unused.levels = lattice.getOption(drop.unused.levels), ..., default.scales = list(), subscripts = !is.null(groups), subset = TRUE) { qdf - as.data.frame(data) histogram(formula, data = qdf, allow.multiple = allow.multiple, outer = outer, auto.key = auto.key, aspect = aspect, panel = panel, prepanel = prepanel, scales = scales, strip = strip, groups = groups, xlab=xlab, xlim=xlim, ylab=ylab, ylim=ylim, type = type, nint = nint, endpoints = endpoints, breaks = breaks, equal.widths = equal.widths, drop.unused.levels = drop.unused.levels, ..., default.scales = default.scales, subscripts = subscripts, subset = subset) } ) Any ideas ? [I'm CC-ing to r-devel, please post follow-ups there] What version of lattice are you using? Please use the latest one, in which histogram is an S3 generic, with only one argument, formula. The eventual solution to your problem may involve changing that, but the first question to ask is whether any other formula makes sense in your context (if not, I would rather keep one argument and dispatch on signature(formula = FLQuant). Disclaimer: I haven't actually had time to check out FLCore yet, I will as soon as I can. Deepayan __ R-help@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
[R] Histogram of multiple series on one histogram
Hello, I have three sample, for example a-c(10,20,10,20,30) b-c(10,20,20,30,30) c-c(20,20,10) I would like to have only one histogram with these series, I try the following code: hist(a) hist(b,add=TRUE,col=red) hist(c,add=TRUE,col=green) but it's not that I want I would like an histogram with, from left to right, count of 10 for a, count of 10 for b, count of 10 for c, count of 20 for a, count of 20 for b, ... not overlapped Thanks -- Alexandre DEPIRE INRETS / GARIG Tel.: (+33) 01 47 40 71 66 Fax: (+33) 01 45 47 56 06 2 av. du général Malleret-Joinville 94114 Arcueil - France __ R-help@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
RE: [R] Histogram of multiple series on one histogram
I think you can use barplot for what you want. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Depire Alexandre Sent: June 3, 2005 12:14 PM To: r-help@stat.math.ethz.ch Subject: [R] Histogram of multiple series on one histogram Hello, I have three sample, for example a-c(10,20,10,20,30) b-c(10,20,20,30,30) c-c(20,20,10) I would like to have only one histogram with these series, I try the following code: hist(a) hist(b,add=TRUE,col=red) hist(c,add=TRUE,col=green) but it's not that I want I would like an histogram with, from left to right, count of 10 for a, count of 10 for b, count of 10 for c, count of 20 for a, count of 20 for b, ... not overlapped Thanks -- Alexandre DEPIRE INRETS / GARIG Tel.: (+33) 01 47 40 71 66 Fax: (+33) 01 45 47 56 06 2 av. du général Malleret-Joinville 94114 Arcueil - France __ R-help@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 __ R-help@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
RE: [R] Histogram of multiple series on one histogram
Something like this!?!? Rnew a [1,] 10 1 [2,] 20 1 [3,] 10 1 [4,] 20 1 [5,] 30 1 [6,] 10 2 [7,] 20 2 [8,] 20 2 [9,] 30 2 [10,] 30 2 [11,] 20 3 [12,] 20 3 [13,] 10 3 Rbarplot(table(new[,2],new[,1]),beside=T,legend.text=c(a,b,c)) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Depire Alexandre Sent: June 3, 2005 12:14 PM To: r-help@stat.math.ethz.ch Subject: [R] Histogram of multiple series on one histogram Hello, I have three sample, for example a-c(10,20,10,20,30) b-c(10,20,20,30,30) c-c(20,20,10) I would like to have only one histogram with these series, I try the following code: hist(a) hist(b,add=TRUE,col=red) hist(c,add=TRUE,col=green) but it's not that I want I would like an histogram with, from left to right, count of 10 for a, count of 10 for b, count of 10 for c, count of 20 for a, count of 20 for b, ... not overlapped Thanks -- Alexandre DEPIRE INRETS / GARIG Tel.: (+33) 01 47 40 71 66 Fax: (+33) 01 45 47 56 06 2 av. du général Malleret-Joinville 94114 Arcueil - France __ R-help@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 __ R-help@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
Re: [R] Histogram of multiple series on one histogram
Hello alexandre, what you are trying to do is *not* an histogram (as a density estimator), if you divide each bar in 3, the surfaces of a won't sum to 1. However a barplot or a barplot2 (in package gplots, bundle gregmisc) would do the trick. See graph 54 on the graph gallery : http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=54 BTW, don't call your vector 'c' unless you want funny things to happen Romain Le 03.06.2005 18:14, Depire Alexandre a écrit : Hello, I have three sample, for example a-c(10,20,10,20,30) b-c(10,20,20,30,30) c-c(20,20,10) I would like to have only one histogram with these series, I try the following code: hist(a) hist(b,add=TRUE,col=red) hist(c,add=TRUE,col=green) but it's not that I want I would like an histogram with, from left to right, count of 10 for a, count of 10 for b, count of 10 for c, count of 20 for a, count of 20 for b, ... not overlapped Thanks -- visit the R Graph Gallery : http://addictedtor.free.fr/graphiques ~ ~~ Romain FRANCOIS - http://addictedtor.free.fr ~~ Etudiant ISUP - CS3 - Industrie et Services ~~http://www.isup.cicrp.jussieu.fr/ ~~ Stagiaire INRIA Futurs - Equipe SELECT ~~ http://www.inria.fr/recherche/equipes/select.fr.html~~ ~ __ R-help@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
Re: [R] Histogram for mixed random variables
Dear Paul, On May 5, 2005, at 6:43 AM, Paul Smith wrote: Dear All I would like to get the histogram for the following model with discrete and continuous random variables: * with probability 1/3, a random number is drawn from the continuous uniform distribution (min=0, max=1); * with probability 2/3, a random number is drawn from a different continuous uniform distribution (min=-1/2, max=1/2). Any help would be most welcome. Thanks in advance, Paul My approach to generate the data would be rMyfun - function(n){ x1 - runif(n, 0, 1) x2 - runif(n, -0.5, 0.5) ifelse(rbinom(n, 1, 1/3), x1, x2) } Hope this helps, Stephen __ R-help@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
[R] Histogram for mixed random variables
Dear All I would like to get the histogram for the following model with discrete and continuous random variables: * with probability 1/3, a random number is drawn from the continuous uniform distribution (min=0, max=1); * with probability 2/3, a random number is drawn from a different continuous uniform distribution (min=-1/2, max=1/2). Any help would be most welcome. Thanks in advance, Paul __ R-help@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
RE: [R] Histogram for mixed random variables
See http://finzi.psych.upenn.edu/R/Rhelp02a/archive/48428.html Andy From: Paul Smith Dear All I would like to get the histogram for the following model with discrete and continuous random variables: * with probability 1/3, a random number is drawn from the continuous uniform distribution (min=0, max=1); * with probability 2/3, a random number is drawn from a different continuous uniform distribution (min=-1/2, max=1/2). Any help would be most welcome. Thanks in advance, Paul __ R-help@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 __ R-help@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
[R] Histogram
Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted Thank you in advance! __ R-help@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
Re: [R] Histogram
On Wed, 20 Apr 2005 17:37:04 +0200 Mag. Ferri Leberl wrote: Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted I think you want a barplot not a histogram. ?barplot Z Thank you in advance! __ R-help@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 __ R-help@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
Re: [R] Histogram
Mag. Ferri Leberl [EMAIL PROTECTED] writes: Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted Thank you in advance! You can't. Histograms are density estimates for continuous outcomes. You can do a barplot, however. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@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
RE: [R] Histogram
From: Mag. Ferri Leberl Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted You can try: hist.factor - function(x, ...) barplot(table(x), ...) f - factor(sample(c(A, B), 50, replace=TRUE)) hist(f) HTH, Andy Thank you in advance! __ R-help@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
RE: [R] Histogram
As Achim said, I would use a barplot instead of an hist. Here's how I would do it: vect-c(a,b,a,b,b,b,a,a,a) a-length(vect[vect==a]) b-length(vect[vect==b]) barplot(c(a,b),names.arg=(c(A,B))) Neuro the Super Hero From: Mag. Ferri Leberl [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject: [R] Histogram Date: Wed, 20 Apr 2005 17:37:04 +0200 Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted Thank you in advance! __ R-help@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 __ R-help@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
RE: [R] Histogram
Of course Andy meant hist.factor(f) In particular you should note that Andy uses the table function to transform ... the data from characters to numbers Tom -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Liaw, Andy Sent: Thursday, 21 April 2005 12:14 AM To: '[EMAIL PROTECTED]'; r-help@stat.math.ethz.ch Subject: RE: [R] Histogram From: Mag. Ferri Leberl Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted You can try: hist.factor - function(x, ...) barplot(table(x), ...) f - factor(sample(c(A, B), 50, replace=TRUE)) hist(f) HTH, Andy Thank you in advance! __ R-help@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 __ R-help@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
RE: [R] Histogram
Mea Culpa I did copy and paste your code to make sure it was an error. I'll go and do it again before I reply. It worked as you expected it to. So I located where I had done it and this is what I found f - factor(sample(c(A, B), 50, replace=TRUE)) hist(f) Error in hist.default(f) : 'x' must be numeric Since I had more than one session open I had inadvertantly pasted the hist.factor - function(x, ...) barplot(table(x), ...) into another window. For some reason or other I have always had finger trouble with the paste commands only in the windows GUI, so I do it one line at a time or past into Tinn-R and select with the alt key. I guess its time for me to actually understand methods, because it's patently obvious I don't even though I was beginning to think I had a handle on them. Tom -Original Message- From: Liaw, Andy [mailto:[EMAIL PROTECTED] Sent: Thursday, 21 April 2005 10:06 AM To: Mulholland, Tom Subject: RE: [R] Histogram Have you tried it? hist.factor() as defined would be the hist method for the factor class, so hist(f) would work if f is a factor. Andy From: Mulholland, Tom Of course Andy meant hist.factor(f) In particular you should note that Andy uses the table function to transform ... the data from characters to numbers Tom -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Liaw, Andy Sent: Thursday, 21 April 2005 12:14 AM To: '[EMAIL PROTECTED]'; r-help@stat.math.ethz.ch Subject: RE: [R] Histogram From: Mag. Ferri Leberl Dear everybody! I am analysing data from an enquette. The answers are either A or B. How can I draw a histogram without transforming the data from characters to numbers? If the data are saved in a list M, hist(M[,1]) returns: Error in hist.default(M[, 1]) : `x' must be numeric Execution halted You can try: hist.factor - function(x, ...) barplot(table(x), ...) f - factor(sample(c(A, B), 50, replace=TRUE)) hist(f) HTH, Andy Thank you in advance! __ R-help@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 -- Notice: This e-mail message, together with any attachments, contains information of Merck Co., Inc. (One Merck Drive, Whitehouse Station, New Jersey, USA 08889), and/or its affiliates (which may be known outside the United States as Merck Frosst, Merck Sharp Dohme or MSD and in Japan, as Banyu) that may be confidential, proprietary copyrighted and/or legally privileged. It is intended solely for the use of the individual or entity named on this message. If you are not the intended recipient, and have received this message in error, please notify us immediately by reply e-mail and then delete it from your system. -- __ R-help@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
[R] Histogram over times (without dates)
Dear Group, Having a character vector like this one: [1] 03:38:55 07:42:38 08:04:27 08:17:13 08:41:14 08:46:58 [7] 08:47:11 08:53:51 08:57:51 08:58:56 I try to do a histogram over times of a day. All I want to know, if my solution is proper or if there is another way to go. There is no Information about the day on which this time occurred. it is unimportant as I want to know at what times on a day a costumer buys anything (times are collected from logfiles). The values span 24 hours (e.g. 00:00:00 to 23:59:59) I converted the characters to chron objects (library(chron)) and then to numeric vectors: ordertm.num - as.numeric(chron(times = ecom$Ordertime)) Then I put the numeric values to hist(), printed the hist without axes=F and constructed my own axis. The result is satisfactory. But as there are so many possibilities with times on R (namely using the POSIX classes) I want to be shure if there is no standard approach to handle such time related problems (note that the date is irrelevant to my problem). have a goof Easter holiday All the best Dubravko Dolic Dubravko Dolic http://www.dolic.de/pagedd.html -- Statistik -- Tel: +49 (0)89-55 27 44 - 4630 Fax: +49 (0)89-55 27 44 - 2463 Email: [EMAIL PROTECTED] Komdat GmbH Nymphenburger Straße 86 / TH 3 80636 München Partners for your success www.komdat.com outbind://96-9676DC1A07BA5142BC1A44984B6E7FAC070052D1AC81378E9342947189B0417601470017F02352D1AC81378E9342947189B0417601470017F7DA/www.komdat.com [[alternative HTML version deleted]] __ R-help@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
Re: [R] Histogram over times (without dates)
Have you looked at the CircStats and circular? They have some plotting functions that may be of help to you. Greg Snow, Ph.D. Statistical Data Center [EMAIL PROTECTED] (801) 408-8111 Dubravko Dolic [EMAIL PROTECTED] 03/24/05 09:38AM Dear Group, Having a character vector like this one: [1] 03:38:55 07:42:38 08:04:27 08:17:13 08:41:14 08:46:58 [7] 08:47:11 08:53:51 08:57:51 08:58:56 I try to do a histogram over times of a day. All I want to know, if my solution is proper or if there is another way to go. There is no Information about the day on which this time occurred. it is unimportant as I want to know at what times on a day a costumer buys anything (times are collected from logfiles). The values span 24 hours (e.g. 00:00:00 to 23:59:59) I converted the characters to chron objects (library(chron)) and then to numeric vectors: ordertm.num - as.numeric(chron(times = ecom$Ordertime)) Then I put the numeric values to hist(), printed the hist without axes=F and constructed my own axis. The result is satisfactory. But as there are so many possibilities with times on R (namely using the POSIX classes) I want to be shure if there is no standard approach to handle such time related problems (note that the date is irrelevant to my problem). have a goof Easter holiday All the best Dubravko Dolic Dubravko Dolic http://www.dolic.de/pagedd.html -- Statistik -- Tel: +49 (0)89-55 27 44 - 4630 Fax: +49 (0)89-55 27 44 - 2463 Email: [EMAIL PROTECTED] Komdat GmbH Nymphenburger Straße 86 / TH 3 80636 München Partners for your success www.komdat.com outbind://96-9676DC1A07BA5142BC1A44984B6E7FAC070052D1AC81378E9342947189B0417601470017F02352D1AC81378E9342947189B0417601470017F7DA/www.komdat.com [[alternative HTML version deleted]] __ R-help@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 __ R-help@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
Re: [R] Histogram over times (without dates)
I do analyses of that sort all the time with air quality data where I wish to begin to understand daily behavior -- works well in doing model evaluation as well. I'd say your approach should give you useful information; however, I'd think you'd also be interested in a possible day of week variation. On Thu, 24 Mar 2005, Greg Snow wrote: Have you looked at the CircStats and circular? They have some plotting functions that may be of help to you. Greg Snow, Ph.D. Statistical Data Center [EMAIL PROTECTED] (801) 408-8111 Dubravko Dolic [EMAIL PROTECTED] 03/24/05 09:38AM Dear Group, Having a character vector like this one: [1] 03:38:55 07:42:38 08:04:27 08:17:13 08:41:14 08:46:58 [7] 08:47:11 08:53:51 08:57:51 08:58:56 I try to do a histogram over times of a day. All I want to know, if my solution is proper or if there is another way to go. There is no Information about the day on which this time occurred. it is unimportant as I want to know at what times on a day a costumer buys anything (times are collected from logfiles). The values span 24 hours (e.g. 00:00:00 to 23:59:59) I converted the characters to chron objects (library(chron)) and then to numeric vectors: ordertm.num - as.numeric(chron(times = ecom$Ordertime)) Then I put the numeric values to hist(), printed the hist without axes=F and constructed my own axis. The result is satisfactory. But as there are so many possibilities with times on R (namely using the POSIX classes) I want to be shure if there is no standard approach to handle such time related problems (note that the date is irrelevant to my problem). have a goof Easter holiday All the best Dubravko Dolic Dubravko Dolic http://www.dolic.de/pagedd.html -- Statistik -- Tel: +49 (0)89-55 27 44 - 4630 Fax: +49 (0)89-55 27 44 - 2463 Email: [EMAIL PROTECTED] Komdat GmbH Nymphenburger Straße 86 / TH 3 80636 München Partners for your success www.komdat.com outbind://96-9676DC1A07BA5142BC1A44984B6E7FAC070052D1AC81378E9342947189B0417601470017F02352D1AC81378E9342947189B0417601470017F7DA/www.komdat.com [[alternative HTML version deleted]] __ R-help@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 __ R-help@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 -- Clint BowmanINTERNET: [EMAIL PROTECTED] Air Quality Modeler INTERNET: [EMAIL PROTECTED] Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 __ R-help@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
[R] histogram and boxplot in a same postscript
Hi, all. I need plot a boxplot under a histogram like below, but some configs are troubled: - the boxplot contours the plot, even if I put bty=n, modifying the histogram plot; - I changed the configs of axis to do a 3x3 inches plot, but the result is 2 different axis. For example, the code below ilustrates this... scores-c(2.0, 0.0, 5.0, 5.0, 5.0, 2.0, 0.0, 5.0, 2.5, 4.0, 5.0, 0.0, 5.0, 0.0, 2.0, 5.0, 5.0, 2.0, 3.0, 3.0) postscript(test.ps, width=3, height=3, horizontal=FALSE, family=Times, paper=special) gra-hist(scores, breaks=((0:11)/2-.2), xlim=c(-1,6), plot=FALSE, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, mgp=c(1.5,.5,0)) yy-ceiling(max(gra$counts)/10)*10 hist(scores, breaks=((0:11)/2-.2), xlim=c(-1,6), ylim=c(0,yy), main=scores, ylab=Freq, xlab=math, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, mgp=c(1.5,.5,0)) boxplot(scores, horizontal=1, add=1, at=-yy/50, boxwex=yy/20, bty=n, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, ann=FALSE) points(q[4], -yy/50, col=1, pch=x, cex=.2) dev.off() Thanks, C. __ R-help@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
Re: [R] histogram and boxplot in a same postscript
Cézar Freitas wrote: Hi, all. I need plot a boxplot under a histogram like below, but some configs are troubled: - the boxplot contours the plot, even if I put bty=n, modifying the histogram plot; You want to set axes = FALSE in boxplot() BTW: What is q[4] in your call to points()? Uwe Ligges - I changed the configs of axis to do a 3x3 inches plot, but the result is 2 different axis. For example, the code below ilustrates this... scores-c(2.0, 0.0, 5.0, 5.0, 5.0, 2.0, 0.0, 5.0, 2.5, 4.0, 5.0, 0.0, 5.0, 0.0, 2.0, 5.0, 5.0, 2.0, 3.0, 3.0) postscript(test.ps, width=3, height=3, horizontal=FALSE, family=Times, paper=special) gra-hist(scores, breaks=((0:11)/2-.2), xlim=c(-1,6), plot=FALSE, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, mgp=c(1.5,.5,0)) yy-ceiling(max(gra$counts)/10)*10 hist(scores, breaks=((0:11)/2-.2), xlim=c(-1,6), ylim=c(0,yy), main=scores, ylab=Freq, xlab=math, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, mgp=c(1.5,.5,0)) boxplot(scores, horizontal=1, add=1, at=-yy/50, boxwex=yy/20, bty=n, cex.axis=.5, cex.main=.5, cex.sub=.5, cex.lab=.5, ann=FALSE) points(q[4], -yy/50, col=1, pch=x, cex=.2) dev.off() Thanks, C. __ R-help@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 __ R-help@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
[R] Histogram Bar Spacing or Border Width
Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. Thank you, Tom Hopper __ R-help@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
Re: [R] Histogram Bar Spacing or Border Width
A histogram is a density estimate (at least as defined in the Encyclopedia of Statistics Sciences, if not in many US Universities). It is an area, not a series of unrelated bars, so it makes no sense to have spaces between the subareas. Unfortunately, hist() will also produce barplots of counts. On Wed, 9 Feb 2005, Thomas Hopper wrote: Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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
Re: [R] Histogram Bar Spacing or Border Width
Tom, I dealt with this once. barplot.data- c(2,3,4,5,6) x- barplot(barplot.data, ylim = c(0,10), space= .9,.9,.9,.9) use the space= to define the spacing between each of your barplot values. If you have groups of bars that you want together, with spaces between the groups, you have to put 0's for each of the unspaced bars. Hope this helps, Zack - Original Message - From: Thomas Hopper [EMAIL PROTECTED] Date: Wednesday, February 9, 2005 7:02 am Subject: [R] Histogram Bar Spacing or Border Width Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. Thank you, Tom Hopper __ R-help@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 __ R-help@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
Re: [R] Histogram Bar Spacing or Border Width
I understand the problem from a statistical perspective, and you make an excellent point (as I have come to expect, reading this list). However, I'm thinking about it from a visual/aesthetic perspective. Let me try this. Plot two histograms side-by-side: x - rnorm(10) par(mfcol=c(1,2)) hist(x) hist(x,col=gray,border=gray) Which one is easier to interpret? To my eyes, the default hist() is, but given the statistical meaning of a histogram, I think I could argue that the gray version is a more accurate representation of the data. The default histogram delimits the space between subareas to make the graph easier to read. I'm just trying to tweak this to further improve it. I don't want to separate the bars so much as control (and, I hope, improve) their appearance. Thanks, Tom On Feb 9, 2005, at 11:06 AM, Prof Brian Ripley wrote: A histogram is a density estimate (at least as defined in the Encyclopedia of Statistics Sciences, if not in many US Universities). It is an area, not a series of unrelated bars, so it makes no sense to have spaces between the subareas. Unfortunately, hist() will also produce barplots of counts. On Wed, 9 Feb 2005, Thomas Hopper wrote: Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 --- In cyberspace, no one can hear you scream. [[alternative text/enriched version deleted]] __ R-help@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
Re: [R] Histogram Bar Spacing or Border Width
I see where you're going...yes, I could create my own histogram distribution from the data and plot it using barplot (in fact, I've already achieved the visual effect I want with barplot, so I could just expand on that). I'm hoping that I can find a way to do it with hist() to avoid duplicating the good work that has already gone in to that function. Thanks, Tom On Feb 9, 2005, at 11:12 AM, Zachary Holden wrote: Tom, I dealt with this once. barplot.data- c(2,3,4,5,6) x- barplot(barplot.data, ylim = c(0,10), space= .9,.9,.9,.9) use the space= to define the spacing between each of your barplot values. If you have groups of bars that you want together, with spaces between the groups, you have to put 0's for each of the unspaced bars. Hope this helps, Zack - Original Message - From: Thomas Hopper [EMAIL PROTECTED] Date: Wednesday, February 9, 2005 7:02 am Subject: [R] Histogram Bar Spacing or Border Width Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. Thank you, Tom Hopper __ R-help@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 --- Never confuse motion with action. -Benjamin Franklin __ R-help@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
Re: [R] Histogram Bar Spacing or Border Width
A hint: hist() does no plotting. That is done by the histogram method of plot(), which you can copy and modify to your own needs/desires. Alternatively you can create myplot() and call myplot(hist(..., plot=TRUE), ...) On Wed, 9 Feb 2005, Thomas Hopper wrote: I understand the problem from a statistical perspective, and you make an excellent point (as I have come to expect, reading this list). However, I'm thinking about it from a visual/aesthetic perspective. Let me try this. Plot two histograms side-by-side: x - rnorm(10) par(mfcol=c(1,2)) hist(x) hist(x,col=gray,border=gray) Which one is easier to interpret? To my eyes, the default hist() is, but given the statistical meaning of a histogram, I think I could argue that the gray version is a more accurate representation of the data. The default histogram delimits the space between subareas to make the graph easier to read. I'm just trying to tweak this to further improve it. I don't want to separate the bars so much as control (and, I hope, improve) their appearance. Thanks, Tom On Feb 9, 2005, at 11:06 AM, Prof Brian Ripley wrote: A histogram is a density estimate (at least as defined in the Encyclopedia of Statistics Sciences, if not in many US Universities). It is an area, not a series of unrelated bars, so it makes no sense to have spaces between the subareas. Unfortunately, hist() will also produce barplots of counts. On Wed, 9 Feb 2005, Thomas Hopper wrote: Is there any way to control the spacing between bars in a histogram, or change the border width (I'm assuming the hist() function, though alternatives are welcome)? I'm interested in changing the visual spacing between columns in a plotted histogram. The general effect I'm looking for can be accomplished in barplots using the width= parameter, but I have not been able to find a way to adjust the apparent spacing in histograms. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 --- In cyberspace, no one can hear you scream. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@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
[R] Histogram
I have data on a single variable LOGT. It has about 300,000 observations. I am trying to make a Histogram out of this data set. Following is my effort. Could anyone help me to solve this error. hist(x) Error in hist.default(x) : `x' must be numeric class(x) [1] data.frame is.object(x) [1] TRUE is.vector(x) [1] FALSE is.numeric(x) [1] FALSE is.factor(x) [1] FALSE note:plot(x) works okay durai __ R-help@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
Re: [R] Histogram
x is not a numeric vector, so R doesn't know how to take a histogram. Here are your clues: class(x) [1] data.frame is.numeric(x) [1] FALSE so, try names(x) I speculate that LOGT is contained in the dataframe x. If so, try hist(x$LOGT) I hope that this helps. Andrew On Tue, Jan 04, 2005 at 03:37:16PM -0800, duraikannan sundaramoorthi wrote: I have data on a single variable LOGT. It has about 300,000 observations. I am trying to make a Histogram out of this data set. Following is my effort. Could anyone help me to solve this error. hist(x) Error in hist.default(x) : `x' must be numeric class(x) [1] data.frame is.object(x) [1] TRUE is.vector(x) [1] FALSE is.numeric(x) [1] FALSE is.factor(x) [1] FALSE note:plot(x) works okay durai __ R-help@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 -- Andrew Robinson Ph: 208 885 7115 Department of Forest Resources Fa: 208 885 6226 University of Idaho E : [EMAIL PROTECTED] PO Box 441133W : http://www.uidaho.edu/~andrewr Moscow ID 83843 Or: http://www.biometrics.uidaho.edu No statement above necessarily represents my employer's opinion. __ R-help@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
[R] Histogram with equal-counts (-probability)
I would like to use R to generate a histogram which has bars of variable bin width with each bar having an equal number of counts. For example, if the bin limits are the quartiles, each bar would represent 1/4 of the total probability in the distribution. An example of such an equal-probability histogram is presented by Nicholas Cox at http://www.stata.com/support/faqs/graphics/histvary.html. Thanks, Hamish __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Histogram without common borders
Is it possible to produce a histogram directly using the hist() function with the common borders removed? It can be done by plotting the histogram object using type 's'teps. my.hist - hist(x,plot=FALSE) plot(my.hist$breaks,c(0,my.hist$counts),type='s') I would appreciate help Ross Darnell -- University of Queensland, Brisbane QLD 4067 AUSTRALIA Email: [EMAIL PROTECTED] Phone: +61 7 3365 6087 Fax: +61 7 3365 4754 http://www.shrs.uq.edu.au/shrs/school_staff/ross_darnell.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram without common borders
Ross Darnell wrote: Is it possible to produce a histogram directly using the hist() function with the common borders removed? It can be done by plotting the histogram object using type 's'teps. my.hist - hist(x,plot=FALSE) plot(my.hist$breaks,c(0,my.hist$counts),type='s') Hello Ross, I think, your approach is not too bad, however you should use S instead of s, see: my.hist - hist(x, lty=1) lines(my.hist$breaks,c(0, my.hist$counts), type='S', lty=dotted, col=red) avoiding unwanted vertical lines with: my.hist - hist(x, lty=0) lines(c(my.hist$breaks, max(my.hist$breaks)), c(0,my.hist$counts,0), type='S') OR simply use filled bars: hist(x, col=grey, lty=0) Hope it helps Thomas P. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Histogram
Dear all, I have a surprising problem with the representation of frequencies in a histogram. Consider, for example, the R code: b-rnorm(2000,3.5,0.3) hist(b,freq=F) When I plotted the histogram, I expected that values in the y-axis (the probability) varied between 0 and 1. Instead, they varied within the range 0-1.3. Have you got any suggestion for obtaining a correct graph with probability within the range 0-1? Thank you very much! Bests /Cristian/ = Cristian Pattaro = Unit of Epidemiology Medical Statistics Department of Medicine and Public Health University of Verona http://biometria.univr.it [EMAIL PROTECTED] = [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram
Cristian Pattaro wrote: Dear all, I have a surprising problem with the representation of frequencies in a histogram. Consider, for example, the R code: b-rnorm(2000,3.5,0.3) hist(b,freq=F) When I plotted the histogram, I expected that values in the y-axis (the probability) varied between 0 and 1. Instead, they varied within the range 0-1.3. Have you got any suggestion for obtaining a correct graph with probability within the range 0-1? Note that width * height (and *not* the height solely) corresponds to the probability in a histogram. Uwe Ligges Thank you very much! Bests /Cristian/ = Cristian Pattaro = Unit of Epidemiology Medical Statistics Department of Medicine and Public Health University of Verona http://biometria.univr.it [EMAIL PROTECTED] = [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram
On Tue, 25 May 2004 12:27:40 +0200 Cristian Pattaro wrote: Dear all, I have a surprising problem with the representation of frequencies in a histogram. Consider, for example, the R code: b-rnorm(2000,3.5,0.3) hist(b,freq=F) When I plotted the histogram, I expected that values in the y-axis (the probability) varied between 0 and 1. Instead, they varied within the range 0-1.3. The y-axis gives the density not the probability! And the density you are sampling from has R dnorm(3.5, mean = 3.5, sd = 0.3) [1] 1.329808 so you shouldn't be surprised by this. Z Have you got any suggestion for obtaining a correct graph with probability within the range 0-1? Thank you very much! Bests /Cristian/ = Cristian Pattaro = Unit of Epidemiology Medical Statistics Department of Medicine and Public Health University of Verona http://biometria.univr.it [EMAIL PROTECTED] = [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
RE: [R] Histogram
On 25-May-04 Cristian Pattaro wrote: I have a surprising problem with the representation of frequencies in a histogram. Consider, for example, the R code: b-rnorm(2000,3.5,0.3) hist(b,freq=F) When I plotted the histogram, I expected that values in the y-axis (the probability) varied between 0 and 1. Instead, they varied within the range 0-1.3. Have you got any suggestion for obtaining a correct graph with probability within the range 0-1? It depends on the widths of the bins, since what is plotted in the histogram when freq=F is vertically scaled so that sum over bins of h*(width of bin) = 1 where h is the height of the histogram bar according to the vertical scale. In other words, hist plots a per-bin estimate of the probability density in the sense of amount of probability per bin divided by width of bin. If your bin widths are narrow (and your SD above is 0,3, so you will get quite narrow bins, 0.2 in this case) and you may well get values exceeding 1. Exactly, indeed, as for the density of the normal distribution itself: (1/(sqrt(2*pi)*sigma))*exp(-0.5* ... ) where small values of sigma give density 1 near x=0. If you need the actual value of the probabilities in the bins (i.e. n_i/N) then you can force it by constructing a new hist object on the lines of h-hist(b,freq=F) h$counts - h$counts/sum(h$counts) plot(h) When I do this with your above example, whereas the original gives a y-axis from 0 to 1.2 with the tallest bar at about 1.3, plot(h) give exactly the same graph but with the y-axis labelled from 0 to 0.25, with the tallest bar at 0.2625, which shows the probabilities. Best wishes, Ted. E-Mail: (Ted Harding) [EMAIL PROTECTED] Fax-to-email: +44 (0)870 167 1972 Date: 25-May-04 Time: 12:15:20 -- XFMail -- __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram ploting
Mateusz == Mateusz £oskot [EMAIL PROTECTED] on Sun, 18 Apr 2004 17:13:34 +0200 writes: Mateusz Hi Christophe, On 4/18/2004 3:17 PM, Christophe Mateusz Pallier wrote: The 'hist' function works on the raw data. In your data set example, you have already computed the number of data points in each bin. Mateusz Yes, you are right. I evidently misunderstood the Mateusz hist function usage described in manuals. What you really want is probably a barplot of N You could display your data: plot(Class,N,'h') Mateusz Yes, that's right. Thank you very much. well, I think you did have real histogram data, and in teaching about graphics I do emphasize the difference between a barplot {in R: plot of table(); space between bars} and a histogram {continuous x; no space between bars}. In this case, I'd rather construct an object of class 'histogram' and plot() it, i.e., call the plot.histogram method: (mids - seq(12.5, 47.5, by = 5)) N - c(3,10, 12,8, 7,3, 4,2) ## Construct breaks from mids in general ## (here, simply br - seq(10,50,by=5) is easier) dx - mean(diff(mids)) br - (mids[-1] + mids[-length(mids)])/2 (br - c(br[1] - dx, br, br[length(br)] + dx)) his - list(breaks=br, counts=N, mids = mids) class(his) - histogram plot(his, main = Histogram of my stuff) Regards, Martin __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] histogram y-scaling
Hello all, Relative to WinXP R1.8 I have two histograms to plot, and for comparison purposes I want them to have the same Y-scaling. I tried to find the size of the bin with the maximum count before generating the histogram, but this did not work (see below). What is a better way? par(mfrow=c(2,1)) # set up for plotting in 2 rows and 1 column x1-seq(-0.5,58.5,1) # make a range of x values for histogram I thought the following lines would allow me to capture the results of the hist function and determine the max bin count for scaling *before* making the plot, but R cleverly saw around my method and plots it anyway. With this code I get two plots. q=hist(mt1,x1) # stick results in a variable... alas also plots cts=q$counts # get the bin counts mct1=max(cts)# how many values in the bin with the most values hist(mt1,x1) # generate histogram plot # go on with histogram #2... Thanks, =Randy= R. Zelick email: [EMAIL PROTECTED] Department of Biology voice: 503-725-3086 Portland State University fax: 503-725-3888 mailing: P.O. Box 751 Portland, OR 97207 shipping: 1719 SW 10th Ave, Room 246 Portland, OR 97201 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] histogram y-scaling
?hist reveals argument plot=TRUE, so try plot=FALSE. On Mon, 19 Apr 2004, Randy Zelick wrote: Hello all, Relative to WinXP R1.8 No such thing. There is R 1.8.0 and R 1.8.1 but not R 1.8. I have two histograms to plot, and for comparison purposes I want them to have the same Y-scaling. I tried to find the size of the bin with the maximum count before generating the histogram, but this did not work (see below). What is a better way? par(mfrow=c(2,1)) # set up for plotting in 2 rows and 1 column x1-seq(-0.5,58.5,1) # make a range of x values for histogram I thought the following lines would allow me to capture the results of the hist function and determine the max bin count for scaling *before* making the plot, but R cleverly saw around my method and plots it anyway. With this code I get two plots. q=hist(mt1,x1) # stick results in a variable... alas also plots cts=q$counts # get the bin counts mct1=max(cts)# how many values in the bin with the most values hist(mt1,x1) # generate histogram plot # go on with histogram #2... Something like q1 - hist(mt1, x1, plot = FALSE) q2 - hist(mt2, x2, plot = FALSE) mctl - max(q1$counts, q2$counts) plot(q1, ylim=c(0, mctl)) plot(q2, ylim=c(0, mctl)) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram ploting
Hello Mateusz, The 'hist' function works on the raw data. In your data set example, you have already computed the number of data points in each bin. What you really want is probably a barplot of N You could display your data: plot(Class,N,'h') Or names(N)-Class barplot(N) Christophe Pallier oskot wrote: Hi, It's my first post on this group. I've just started learning using R and I like it ;-) I have I think simple question. I'm trying to plot a histogram for my data set. My data set is defined as follows: ClassN 12.53 17.510 22.512 27.58 32.57 37.53 42.54 47.52 Class means middle of set of my ranges I define. N column stores number of measurements counted to particular class. And now I would like to plot a simple histogram presenting numbers of measurements in each class. As I read in manual, hist function takes x (my N) as the first param but I can not identify how should I pass my class ranged into hist function. I believe you can understand my problem ;-))) Could anyone help me ? Kind regards __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Histogram ploting
Hi Christophe, On 4/18/2004 3:17 PM, Christophe Pallier wrote: The 'hist' function works on the raw data. In your data set example, you have already computed the number of data points in each bin. Yes, you are right. I evidently misunderstood the hist function usage described in manuals. What you really want is probably a barplot of N You could display your data: plot(Class,N,'h') Yes, that's right. Thank you very much. Kind regards -- Mateusz oskot mateusz at loskot dot net __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html