I'm trying to shade part of a density plot. The code I'm trying (using the Old Faithful data as an example) is something like this: # The Old Faithful geyser data data(faithful) d <- density(faithful$eruptions, bw = "sj") plot(d) polygon(d[d$x>4], col = "wheat") I expected that the part of the curve to the right of 4 on the x axis should be shaded, but nothing gets shaded at all. In fact, when I just try to print d[d$x>4] I get many lines of $"NA" NULL I must be mistaken in my understanding of density objects. Could someone clear up my mistake? Thanks very much. -- Stuart Luppescu -=- s-luppescu at uchicago.edu University of Chicago -=- CCSR $B:MJ8$HCRF`H~$NIc(B -=- Kernel 2.4.18-xfs checkuary, n: The thirteenth month of the year. Begins New Year's Day and ends when a person stops absentmindedly writing the old year on his checks. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 240 bytes Desc: This is a digitally signed message part Url : https://stat.ethz.ch/pipermail/r-help/attachments/20020519/f5e01aa2/attachment.bin
Stuart Luppescu wrote:> > I'm trying to shade part of a density plot. The code I'm trying (using > the Old Faithful data as an example) is something like this: > > # The Old Faithful geyser data > data(faithful) > d <- density(faithful$eruptions, bw = "sj") > plot(d) > polygon(d[d$x>4], col = "wheat") > > I expected that the part of the curve to the right of 4 on the x axis > should be shaded, but nothing gets shaded at all. In fact, when I just > try to print d[d$x>4] I get many lines of > $"NA" > NULL > I must be mistaken in my understanding of density objects. Could someone > clear up my mistake? Thanks very much.That's because d is essentially a list, if you do something like R> sub.x <- d$x[d$x > 4] R> sub.y <- d$y[d$x > 4] R> polygon(c(min(sub.x), sub.x), c(0, sub.y), col = "wheat") you should get the desired result. Z> -- > Stuart Luppescu -=- s-luppescu at uchicago.edu > University of Chicago -=- CCSR > $B:MJ8$HCRF`H~$NIc(B -=- Kernel 2.4.18-xfs > checkuary, n: The thirteenth month of the year. Begins New > Year's Day and ends when a person stops absentmindedly > writing the old year on his checks. > > > ------------------------------------------------------------------------ > Name: signature.asc > signature.asc Type: application/pgp-signature > Description: This is a digitally signed message part-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Stuart Luppescu wrote:> > I'm trying to shade part of a density plot. The code I'm trying (using > the Old Faithful data as an example) is something like this: > > # The Old Faithful geyser data > data(faithful) > d <- density(faithful$eruptions, bw = "sj") > plot(d) > polygon(d[d$x>4], col = "wheat")Hmm. Have a look at str(d) to see that d is a density object, which is a list of objects of different lengths, so indexing as you did doesn't work ... What about taking index <- d$x > 4 and working with d$x[index] and d$y[index] to generate the shading? Uwe Ligges> I expected that the part of the curve to the right of 4 on the x axis > should be shaded, but nothing gets shaded at all. In fact, when I just > try to print d[d$x>4] I get many lines of > $"NA" > NULL > I must be mistaken in my understanding of density objects. Could someone > clear up my mistake? Thanks very much.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Marc Schwartz
2002-May-20 13:25 UTC
[R] Possible x-axis label bug in barplot() when "plot = F"
Hi all, I have searched the R-help archives and the bug tracking system and could not find this one. I am hoping that someone can either reproduce this or tell me that I am missing a step that is the proximate cause. I am running R 1.5.0 Patched (May 15, 2002 compiled version kindly distributed by Prof. Ripley) under WinXP Pro on a P4m platform, which is up to date with all current patches. The display device is a UXGA 1600 x 1200 LCD panel running in 32 bit mode. If additional HW information is required, let me know. The issue appears to be the horizontal positioning of the x-axis labels when "plot = F" in barplot(). The following simple code segments, if reproducible, should help demonstrate:> plot.new() > midpts <- barplot(1:10, axes = F, axisnames = F) > axis(1, at = midpts)The above code results in a barplot with no axis labels initially. The call to axis() then results in appropriate x-axis labels under the midpts of the vertical bars. The x-axis labels are the midpts values.> plot.new() > midpts <- barplot(1:10, axes = F, axisnames = F, plot = F) > axis(1, at = midpts)The above code, now with "plot = F", results in a barplot with no bars or axis labels initially. When I call axis(), the first axis label ("0.7") is offset well to the right, such that it is the only label displayed. Am I missing a step that sets the x-axis scaling when "plot = F" or is this a bug? If more information is required, let me know. Thanks, Marc Schwartz -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Maybe Matching Threads
- floor(NaN) problem fixed in massdist.c (PR#291)
- finite mixture model (2-component gaussian): plotting component gaussian components?
- Omitting members of a sequence
- Assignment working differently inside ifelse()
- Order of terms in formula changes aov() results