[R] Lattice - parallel: xlim and adding lines
Sundar Dorai-Raj
sundar.dorai-raj at pdf.com
Wed Mar 30 01:04:14 CEST 2005
T.A.Wassenaar wrote on 3/29/2005 4:17 PM:
>
> 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
>
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 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 2:17 PM:
>>
>>>
>>> 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
>>>
>>
>> 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
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list