[R] plotting curve in xYplot -- using panel.curve
John Poulsen
jpoulsen at zoo.ufl.edu
Sat Jan 24 13:51:15 CET 2009
Hello Deepayan,
Thanks for your help - it works great now. Indeed, there was also a
problem with the way I specified the curve. Once I made the suggests
you suggested I ended up with an error:
//"Error using packet 1 argument "subscripts" is missing, with no default"
//which I fixed by adding "subscripts" to my panel function.
I am including the fixed code below in case it can help anyone else.
Thanks,
John
-----------------------------------
a=0.07; b=74.3; c=0.43
sds=rep(c(0,3,5,10,20,50,200), each=3)
y1=c(0,0,0.16, 0, 0.33,0.5, 0.16, 0.83, 1.16, 0.67, 0.5, 1.16, 0.83,
2.33, 3.6, 5.5, 4.33, 1.16, 22, 13, 12)
lo=y1-0.1*y1
hi=y1+0.1*y1
# Figure 1
xYplot(Cbind(y1, lo, hi)~jitter(sds, amount=1),
method="bars",ylim=c(0,max(hi)+1),
ylab="Y", xlab="X")
# Figure 2
myPanel = function(x, y, subscripts, ...) {
panel.xYplot(x, y, subscripts = subscripts, ...)
panel.curve(a*(x+c)/(1+(a*(x+c)/b)), from=0, type="l", lwd=1,
col="black")
}
xYplot(Cbind(y1, lo, hi)~jitter(sds, amount=1),
method="bars",ylim=c(0,max(hi)+1),
ylab="Y", xlab="X", panel=myPanel)
Deepayan Sarkar wrote:
> On Fri, Jan 23, 2009 at 12:46 PM, Dieter Menne
> <dieter.menne at menne-biomed.de> wrote:
>
>>
>> John Poulsen wrote:
>>
>>> I am trying to plot a curve over points plotted with se's in xYplot (see
>>> example below). I can get Figure 1 below to plot the data with error.
>>> However, I keep getting a the error message
>>>
>>> "Error using packet 1 object "y" not found"
>>>
>>> Can anyone see what I am doing wrong?
>>>
>>> Thanks!
>>> John
>>>
>>> -------------------------------
>>>
>>> a=0.002; b=31.7; c=0.51
>>> sds=rep(c(0,3,5,10,20,50,200), each=3)
>>> y1=c(0,0,0.16, 0, 0.33,0.5, 0.16, 0.83, 1.16, 0.67, 0.5, 1.16, 0.83,
>>> 2.33, 3.6, 5.5, 4.33, 1.16, 22, 13, 12)
>>> lo=y1-0.1*y1
>>> hi=y1+0.1*y1
>>>
>>> # Figure 1
>>> xYplot(Cbind(y1, lo, hi)~jitter(sds, amount=1),
>>> method="bars",ylim=c(0,max(hi)+1),
>>> ylab="Y", xlab="X")
>>>
>>> # Figure 2
>>> xYplot(Cbind(y1, lo, hi)~jitter(sds, amount=1),
>>> method="bars",ylim=c(0,max(hi)+1),
>>> ylab="Y", xlab="X",
>>> panel=function(...){
>>> panel.xYplot(x,y,...)
>>> panel.number=panel.number()
>>> panel.curve(curve(a*(x+c)/1+a*b*(x+c), from=0, type="l", lwd=2))
>>> }
>>> )
>>>
>>>
>>>
>> John Poulsen <jpoulsen <at> zoo.ufl.edu> writes:
>>
>>
>>> I am trying to plot a curve over points plotted with se's in xYplot (see
>>> example below). I can get Figure 1 below to plot the data with error.
>>> However, I keep getting a the error message
>>>
>>> "Error using packet 1 object "y" not found"
>>> -------------------------------
>>>
>>> a=0.002; b=31.7; c=0.51
>>> sds=rep(c(0,3,5,10,20,50,200), each=3)
>>> y1=c(0,0,0.16, 0, 0.33,0.5, 0.16, 0.83, 1.16, 0.67, 0.5, 1.16, 0.83,
>>> 2.33, 3.6, 5.5, 4.33, 1.16, 22, 13, 12)
>>> lo=y1-0.1*y1
>>> hi=y1+0.1*y1
>>>
>> ..
>>
>>> # Figure 2
>>> xYplot(Cbind(y1, lo, hi)~jitter(sds, amount=1),
>>> method="bars",ylim=c(0,max(hi)+1),
>>> ylab="Y", xlab="X",
>>> panel=function(...){
>>> panel.xYplot(x,y,...)
>>> panel.number=panel.number()
>>> panel.curve(curve(a*(x+c)/1+a*b*(x+c), from=0, type="l", lwd=2))
>>> }
>>> )
>>>
>>>
>> Try
>> panel=function(x,y,...){
>>
>> Looks like it is not exactly what you expected, but the error is gone.
>>
>
> Also, this line doesn't make sense:
>
> panel.curve(curve(a*(x+c)/1+a*b*(x+c), from=0, type="l", lwd=2))
>
> You probably want
>
> panel.curve(a*(x+c)/1+a*b*(x+c), from=0, type="l", lwd=2)
>
> -Deepayan
>
>
More information about the R-help
mailing list