R-beta: pairs-plot

Andreas Weingessel Andreas.Weingessel at ci.tuwien.ac.at
Wed Jan 14 18:49:46 CET 1998


>>>>> On Wed, 14 Jan 1998 09:12:34 -0800 (PST),
>>>>> Thomas Lumley wrote:

> On Wed, 14 Jan 1998, Andreas Weingessel wrote:
>> 
>> I have the following problem. I have some multidimensional data points
>> "x" and a curve "fit" fitted to these points. How can I combine
R> pairs(x)
>> and
R> pairs(fit,panel=lines)
>> in one plot, so that I can see how good the curve fits the data?
>> 
>> A command like
R> pairs(x, panel=function(x,y) {points(x,y); lines(lowess(x,y))})
>> does not work, since I fit the curve in all dimensions at once.


> You can write

> fit<-compute.fit.somehow()
> pairs(x, fitted.lines=fit, 
> 	panel=function(x,y,fitted.lines){
> 		points(x,y)
> 		however.you.display.lines(fitted.lines,x,y)
> 		}
> 	)

> that is, pass the fit as an extra argument into pairs().

Thanks, but it does not work in this way. If I try it with the standard
lines command, I get
Error: x and y lengths differ

The reason is that x and fit are two matrices of the same size (100x4
for example). For each pair of columns of x, the pairs function passes
these two column vectors (length 100) and the whole fit matrix (length
400) to the function defined in panel. I see no way to rewrite the
panel function in a way that I can extract the appropriate columns of
fit.

Passed on your suggestions I came up with the following possibilty:

R> dim(x)
[1] 100   4
R> dim(fit)
[1] 100   4
R> xfit <-matrix(0,200,4); xfit[1:100,] <- x; xfit[101:200,] <- fit
R> pairs(xfit, panel=function(x,y){
         n <- length(x)/2
         points(x[1:n],y[1:n])
         lines(x[(n+1):(2*n)],y[(n+1):(2*n)])})

But this is rather complicated. I think the only clean way for this
and related problems would be a parameter "new" which can be passed to
the pairs command (or any other plot command). Something like
R> pairs(x)
R> pairs(fit, panel=lines, new=F)


	Andreas
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list