[R] xyplot help
array chip
arrayprofile at yahoo.com
Fri Jul 9 00:57:34 CEST 2010
Hi, I am learning xyplot. I have an example dataset attached.
plotdata<-read.table("plotdata.txt",sep='\t',header=T,row.names=1)
head(plotdata,n=4)
y x type
1 -4.309601 -0.7448405 A
2 -4.715421 0.7875994 A
3 -2.310638 0.5455310 A
4 -2.685803 10.4116868 A
xyplot(y~x,groups=type,plotdata, auto.key=T)
This shows different colors for different levels of "type".
Now, I want to add a fitted line to the plot, the formula is
-1.324+0.1117*x-0.0006357*x*x
I tried the following code to do this:
xyplot(y~x,groups=type,plotdata, auto.key=T
, panel = function(x,y) {
panel.xyplot(x,y, type='p')
x<-sort(x)
panel.lines(x,-1.324+0.1117*x-0.0006357*x*x)
})
Now, it doesn't show different colors for different levels of "type". How can I
restore that?
Also, is there anyway to put the legend at bottom of the plot (instead at the
top right now)? And is there anyway to print legend horizontally, instead of
vertically as shown right now?
Thanks
John
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: plotdata.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20100708/b501213f/attachment.txt>
More information about the R-help
mailing list