Hello again,
I have been trying to add an expression to the strips in xYplot to no
avail. For example, in the code below, the text in the strips for each
panel is "Anls" and "Plts". However, I would like it to add
"Anls km^2"
and "Plants km^2" with the exponents raised.
I tried resetting the name of my groups in the dataframe before
plotting, but the dataframe only recognized the entire expression (e.g.
expression(paste("Anls", km^2,sep=" ")) and not Anls km2 -
which should
not have surprised me.
Any ideas? Thanks for any help you can provide.
John
x1=rseq(1,30,0.5)
y1=x1^2
y2=10*(x1^2)
ycomb=c(y1,y2)
y.up=ycomb+0.1*ycomb
y.low=ycomb-0.1*ycomb
grp=rep(c("Anls","Plts"),each=length(x1)))
dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F)
colnames(dat)=c("ycomb","y.up","y.low","x1")
with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp),
data=dat,type="l", method="bands",
scales=list(y=list(relation="free"),
x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,10000))))
Hi John,
a solution to your problem would be using strip.custom like this:
...
with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp),
data=dat,type="l", method="bands",
scales=list(y=list(relation="free"),x=list(alternating=c(1,1,1))),
ylim=list(c(0,1200),c(0,10000)),
strip=strip.custom(factor.levels=c(expression("Anls
km"^2),expression("Plants km"^2)))))
Best wishes,
Christoph
Wednesday, April 9, 2008, 2:39:09 PM, you wrote:
> Hello again,
> I have been trying to add an expression to the strips in xYplot to no
> avail. For example, in the code below, the text in the strips for each
> panel is "Anls" and "Plts". However, I would like it
to add "Anls km^2"
> and "Plants km^2" with the exponents raised.
> I tried resetting the name of my groups in the dataframe before
> plotting, but the dataframe only recognized the entire expression (e.g.
> expression(paste("Anls", km^2,sep=" ")) and not Anls
km2 - which should
> not have surprised me.
> Any ideas? Thanks for any help you can provide.
> John
> x1=rseq(1,30,0.5)
> y1=x1^2
> y2=10*(x1^2)
> ycomb=c(y1,y2)
> y.up=ycomb+0.1*ycomb
> y.low=ycomb-0.1*ycomb
> grp=rep(c("Anls","Plts"),each=length(x1)))
> dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F)
>
colnames(dat)=c("ycomb","y.up","y.low","x1")
> with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp),
> data=dat,type="l", method="bands",
> scales=list(y=list(relation="free"),
>
> x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,10000))))
> ______________________________________________
> R-help at r-project.org 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.
***************************************************************
Dr. Christoph Meyer
Institute of Experimental Ecology
University of Ulm
Albert-Einstein-Allee 11
D-89069 Ulm
Germany
Phone: ++49-(0)731-502-2675
Fax: ++49-(0)731-502-2683
Mobile: ++49-(0)1577-156-7049
E-mail: christoph.meyer at uni-ulm.de
http://www.uni-ulm.de/nawi/nawi-bio3.html
Hello Christoph, Oops, I see that the factor.levels function is in the help menu for strip.default. I had tried it, but not specified it correctly. Thanks again for you help, John Christoph Meyer wrote:> Hi John, > > a solution to your problem would be using strip.custom like this: > > ... > with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), > data=dat,type="l", method="bands", > scales=list(y=list(relation="free"),x=list(alternating=c(1,1,1))), > ylim=list(c(0,1200),c(0,10000)), > strip=strip.custom(factor.levels=c(expression("Anls km"^2),expression("Plants km"^2))))) > > Best wishes, > Christoph > > > Wednesday, April 9, 2008, 2:39:09 PM, you wrote: > >> Hello again, > >> I have been trying to add an expression to the strips in xYplot to no >> avail. For example, in the code below, the text in the strips for each >> panel is "Anls" and "Plts". However, I would like it to add "Anls km^2" >> and "Plants km^2" with the exponents raised. > >> I tried resetting the name of my groups in the dataframe before >> plotting, but the dataframe only recognized the entire expression (e.g. >> expression(paste("Anls", km^2,sep=" ")) and not Anls km2 - which should >> not have surprised me. > >> Any ideas? Thanks for any help you can provide. > >> John > >> x1=rseq(1,30,0.5) >> y1=x1^2 >> y2=10*(x1^2) >> ycomb=c(y1,y2) >> y.up=ycomb+0.1*ycomb >> y.low=ycomb-0.1*ycomb >> grp=rep(c("Anls","Plts"),each=length(x1))) >> dat=as.data.frame(cbind(ycomb, y.up, y.low, rep(x1,2)),stringsAsFactors=F) >> colnames(dat)=c("ycomb","y.up","y.low","x1") > >> with(dat,xYplot(Cbind(ycomb, y.up, y.low)~x1|factor(grp), >> data=dat,type="l", method="bands", >> scales=list(y=list(relation="free"), >> >> x=list(alternating=c(1,1,1))),ylim=list(c(0,1200),c(0,10000)))) > >> ______________________________________________ >> R-help at r-project.org 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. > > > > *************************************************************** > Dr. Christoph Meyer > Institute of Experimental Ecology > University of Ulm > Albert-Einstein-Allee 11 > D-89069 Ulm > Germany > Phone: ++49-(0)731-502-2675 > Fax: ++49-(0)731-502-2683 > Mobile: ++49-(0)1577-156-7049 > E-mail: christoph.meyer at uni-ulm.de > http://www.uni-ulm.de/nawi/nawi-bio3.html > *************************************************************** > > >