[R] curve

Sarah Goslee sarah.goslee at gmail.com
Tue Dec 14 15:37:09 CET 2010


Val,

Here's the complete console output. The graph produced is at:
http://www.functionaldiversity.org/temp/curve.png

R version 2.12.0 (2010-10-15)
Copyright (C) 2010 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-redhat-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> ls()
character(0)
>
> test<- rnorm(5000,1000,100)
> test1 <- subset(test, subset=(test > 1100))
> d <- density(test)
>
> png("curve.png")
> plot(d, main="Density of production", xlab="")
>
> xarea <- c(1100, d$x[d$x > 1100], c(max(test)))
> yarea <- c(0, d$y[d$x > 1100], 0)
>
>
> polygon(xarea, yarea, col="blue")
>
> curveheight <- d$y[abs((d$x - mean(test1))) == min(abs((d$x - mean(test1))))]
> segments(x0=mean(test1), y0=0, x1=mean(test1), y1=curveheight, col="red", lwd=2)
> dev.off()
null device
          1
>

Sarah


On Tue, Dec 14, 2010 at 8:59 AM, Val <valkremk at gmail.com> wrote:
> Hi Sara,
>
> Could you please send me your output as an attached file if it is possible?
>
> Thanks
>
>
>> >> 1. to shade or color (blue) the curve using the criterion that any
>> >> values
>> >> greater than 11,000
>> >
>> > I think I was not clear in the above point. I want shade not the line
>> > but
>> > the area under the curve,
>>
>> Here's an example of how to do that using polygon:
>> http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=7
>>
>> > and
>> > Your last line of code,
>> > segments(x0=mean(test1), y0=0, y1=curveheight)
>> >
>> > gave me the  following error message
>> >
>> > Error in segments(x0 = mean(test1), y0 = 0, y1 = curveheight) :
>> >  element 3 is empty;
>> >   the part of the args list of '.Internal' being evaluated was:
>> >   (x0, y0, x1, y1, col = col, lty = lty, lwd = lwd, ...)
>> >
>> > could you check it please
>>
>> I checked it before I sent it to you. The code I provided works correctly
>> on my computer.  (R 2.12.0, Linux).
>>
>> You could try this statement instead:
>> segments(x0 = mean(test1), y0 = 0, x1=mean(test1), y1 = curveheight)
>>
>> Sarah
>>
>> --



-- 
Sarah Goslee
http://www.functionaldiversity.org



More information about the R-help mailing list