Skip to content

Lattice - parallel: xlim and adding lines

5 messages · T.A.Wassenaar, Sundar Dorai-Raj, Deepayan Sarkar

#
Hi,

I'm trying to set the minimum and maximum in a parallel 
plot, but trying xlim=c(-1,1) gives strange results. Am I 
missing something? The call I give is:

parallel(~X[,c(6,9,12,15,18)]|X$ff,X,panel=panel.parallel.new,groups=X$protein,layout=c(3,1),xlim=c(-1,1))

Besides, I would like to add a reference line to the plot, 
but can't find how to do that.

I hope someone can give me a hint or two.

Thanks in advance,

Tsjerk
#
T.A.Wassenaar wrote on 3/29/2005 2:17 PM:
Tsjerk,

I don't think you'll get much help without knowing, first, what 
"strange" means, and second, what "panel.parallel.new" does. And you can 
always add a reference line by using panel.abline in your panel function.

And, from the signature:

PLEASE do read the posting guide! 
http://www.R-project.org/posting-guide.html

--sundar
#
Hi Sundar,

Thanks for the reply. And, oops, the panel.parallel.new 
shouldn't be in there. That is a revised panel function to 
color according to a group. As with strange, that would 
generally be 'not-expected', i.e., in the present case, 
not having an x-axis running from -1 to 1 for all ranges. 
I would at least expect to have zero in the middle, but 
that is not so. Excuse me for not expanding 'strange' 
previously. I have read the guide.., some while ago.

Thanks again,

Tsjerk

On Tue, 29 Mar 2005 14:42:05 -0600
Sundar Dorai-Raj <sundar.dorai-raj at pdf.com> wrote:
#
T.A.Wassenaar wrote on 3/29/2005 4:17 PM:
Tsjerk,

 From panel.parallel, the x values are being scaled to c(0, 1)

x <- (as.numeric(z[subscripts[i], , ]) - llim)/dif

This puts the "Min" at x == 0 and the "Max" at x == 1 on the x-axis. If 
you want to leave it in the raw scale of the x, you will have to write 
your own panel and prepanel function, or simply determine what xlim = 
c(-1, 1) is in the scaled coordinates.

E.g.

lin.scale <- function(x, a = 0, b = 1, new.x = NULL) {
   slope <- (b - a)/diff(range(x))
   inter <- a - slope * min(x)
   if(is.null(new.x)) {
     inter + slope * x
   } else {
     inter + slope * new.x
   }
}
xlim <- lin.scale(range(iris[1:4]), new.x = c(-2, 10))
parallel(~ iris[1:4] | Species, iris, xlim = xlim)

The next question would be how to set the x labels to something other 
than "Min" and "Max" because (to me) they appear to be hard-coded in 
parallel. I will leave that question to Deepayan.

As for adding lines, you will also have to scale your reference line to 
the panel units. For my example, each panel has a x range of c(0, 1) and 
a y range of c(1, 4). E.g.

my.panel.parallel <- function(z, subscripts, col = superpose.line$col,
                               lwd = superpose.line$lwd,
                               lty = superpose.line$lty, ...) {
   superpose.line <- trellis.par.get("superpose.line")
   panel.abline(v = 0.5, lwd = 3)
   panel.parallel(z, subscripts, col, lwd, lty, ...)
}

HTH,

--sundar
#
On Tuesday 29 March 2005 17:04, Sundar Dorai-Raj wrote:
Why???  Why on earth would [-1,1] be something you ``expect'' and [0,1] 
be something ``strange''? As far as I can see, neither are documented 
(and hence you shouldn't expect anything).

You can of course set 'xlim=c(0,1)', but the better way of doing that 
would have been 'scales=list(x = list(axs = "i")))'. Unfortunately, 
this doesn't currently work in 'parallel', which is a bug.

It's still not very clear to me what you want to.
That doesn't really make sense. The whole point of a parallel plot is to 
show several variables (with different ranges) in a single plot with a 
common axis. This is done by transforming (shifting and linearly 
scaling) each variable to have a common range. As such, there's no 
'natural choice' for this common range, [0,1] is just as good as any 
other [a,b] for -Inf < a < b < Inf.

If you want to do something else, you might as well write your own 
prepanel and panel functions.
My bad (relic of early days). I'll fix it so that they can be overridden 
by 'scales'.