[R] pairs, panel.functions, xlim and ylim
"Jens Oehlschlägel"
joehl at gmx.de
Wed Sep 22 19:32:34 CEST 2004
Valerie,
A bit ugly, because you must ignore some warnings,
but for me works the code below.
Best
Jens OehlschlÃ¤gel
x <- rnorm(100, sd=0.2)
x <- cbind(x=x-0.1, y=x+0.1)
pairs(x
, panel=function(x,y){
function to be called with xlim=, ylim= parameters
points(x, y)
abline(0,1)
}
)
pairs(x
, panel=function(x,y, ...)
{ # adding the three points here allows your panel function to accept the
additional xlim=, ylim= parameters
points(x, y)
abline(0,1)
}
, xlim=c(-1, 1)
, ylim=c(-1, 1)
)
> I have the following problem.
> I wanted to get a matrix of scatterplots and I used pairs.
> I wanted to add the line y=x in each plot and I created a panel
> function for this scope.
> I used points and abline in the following way:
>
> ## put y=x in each plot
> panel.lin<- function(x, y)
> {
> points(x,y, pch=21, bg=par("bg"), col = "black",cex=2)
> abline(0,1,lwd=2, col="red")
> }
>
> and it works.
> Now, I want that each plot has the same scale on the axis and I try
> with this modification:
>
> ## put y=x in each plot - same scale for all the plots
> panel.lincor<- function(x, y)
> {
> points(x,y, pch=21, bg=par("bg"), col =
> "black",cex=2,xlim=c(-1,1),ylim=c(-1,1))
> abline(0,1,lwd=2, col="red")
> }
>
> but R tells me that xlim and ylim couldn't be set in high level plot
> functions.
> I try to use plot() instead of points, but I realized immediately that
> I can't use plot as a panel function.
> I know I could have added xlim and ylim directly in pairs() function,
> if I hadn't had a panel function, but I need the line y=x in every plot
> and I don't know other ways to get it.
> Any idea?
> Thank you very much
> Valeria Edefonti
--
GMX ProMail mit bestem Virenschutz http://www.gmx.net/de/go/mail
+++ Empfehlung der Redaktion +++ Internet Professionell 10/04 +++
More information about the R-help
mailing list