[R] xyplot questions - axis and plotting two things in same panel

Karin Lagesen karinlag at studmed.uio.no
Thu Jun 26 11:03:58 CEST 2008


"Deepayan Sarkar" <deepayan.sarkar at gmail.com> writes:

> On 6/25/08, Franz Mueter <fmueter at alaska.net> wrote:
>> As for your first problem, try:
>>
>>  xyplot(numbers~breaks|moltype, groups = type, data = alldata, type = "l")
>>
>>
>>  -----Original Message-----
>>  From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
>>  Behalf Of Karin Lagesen
>>  Sent: Wednesday, June 25, 2008 2:13 AM
>>  To: r-help at r-project.org
>>  Subject: [R] xyplot questions - axis and plotting two things in same panel
>
> [...]
>
>>  I am also wondering about whether it is possible to change the x axis
>>  scale here. I have data going from 0 to 35, but most of the
>>  interesting stuff is between 0 and 5. Thus I am wondering if there is
>>  any way of specifying that the 0 to 5 range should take up 30 % of the
>>  x axis (or something like that) and gradually shrink the axis after
>>  that. I have tried doing log on the x axis, but I have a lot of zeros
>>  in my data set that really breaks everything.
>
> Rather than having the software support arbitrary axis
> transformations, it would be simpler to transform the data; e.g.,
>
> xyplot(numbers~asinh(breaks) | moltype, groups = type, data = alldata,
> type = "l")
>
> That still leaves the problem of "nice" axis labels in the original
> scale. That is in general a hard problem. For special cases, you can
> specify explicit tick positions (in the transformed scale) and
> associated labels (in the original scale) using the 'scales' argument.

Since I search the archives of this list quite a lot, I thought I'd
just post the results I came up with and which worked nicely for me.

I ended up with using the sqrt transformation, which gave me a very
nice plot. For the axis I used the scales argument, as follows:

# the max value on the x axis for my data is 40
labels = seq(0,40, by = 5)
atvalues = sqrt(seq(0,40, by = 5))
#the plot itself
xyplot(numbers~sqrt(breaks)|moltype, groups = type, data = alldata, type = "l", scales = list(at = atvalues, labels = labels))

worked like a charm!

Thanks a lot for your help!

Karin
-- 
Karin Lagesen, PhD student
karin.lagesen at medisin.uio.no
http://folk.uio.no/karinlag



More information about the R-help mailing list