Thanks! (was [R] panel.axis() & grid/lattice settings)

From: Pikounis, Bill [CNTUS] <BPikouni_at_cntus.jnj.com>
Date: Fri 03 Jun 2005 - 07:50:05 EST


Deepayan, Paul:
Thanks very much for the very useful leads. I just spent some time this afternoon implementing your suggestions and my early test results are very encouraging.

Paul, I understand the potential device re-sizing issue with the convert family of functions in grid, and will be in touch in case it becomes problematic for my applications. I very much look forward to your upcoming "R Graphics" book and wish you the best in completing it.

Best Regards,
Bill

> -----Original Message-----
> From: Paul Murrell [mailto:p.murrell@auckland.ac.nz]
> Sent: Thursday, June 02, 2005 4:57 PM
> To: Pikounis, Bill [CNTUS]
> Cc: Deepayan Sarkar; r-help@stat.math.ethz.ch
> Subject: Re: [R] panel.axis() & grid/lattice settings
>
>
> Hi
>
>
> Deepayan Sarkar wrote:
> > On Wednesday 01 June 2005 05:43, Pikounis, Bill [CNTUS] wrote:
> >
> >>Hello,
> >>I wish to customize the tick marks and labels of axes in
> panels produced by
> >>high-level lattice functions, namely xyplot. I know I can
> use the scales
> >>argument to specify values for rot, cex, etc. in the top-level call.
> >>
> >>However, I am interested in determining values for cex and
> rot based on the
> >>current panel / viewport and device. More specifically, I
> would like to
> >>make adjustments when tick labels overlap on the x-axis,
> such as labels of
> >>a factor. If I use base graphics, par("cin") or par("cxy")
> or strwidth(),
> >>etc. can be used to develop an algorithm to adjust cex or/and rot if
> >>needed.
> >>
> >>I am trying to determine the parameters/settings in grid
> analogous to
> >>par("cin"), etc. mentioned above, knowing that par() has no
> effect in
> >>lattice / grid. I have dug around the sources for grid and
> lattice but
> >>cannot seem to come up with such parameters -- most notably
> something like
> >>strwidth(). I see that panel.axis() has a check.overlap argument for
> >>labels, but I could not trace down the actual code to see
> how that works.
> >>What have I overlooked, or where should I be looking?
> >
> >
> > Paul may be able to give a more insightful answer, but grid
> allows a string to
> > determine it's width in terms of itself, e.g.:
> >
> > unit(1, "strwidth", data = "foo")
>
>
> Or just stringWidth("foo") (and of course stringHeight("foo")).
>
>
> > If you want to convert that into, say, inches, you could use
> >
> >
> >>convertX(unit(1, "strwidth", data = "foo"), "inches", TRUE)
> >
> > [1] 0.2344092
> >
> > I think this would depend on the gpars() in effect, in
> particular fontsize.
>
>
> Yep. There's also grobWidth(textGrob("foo")), which gives
> you not just
> the size of a string, but the size of a text graphical object. The
> difference is that a text graphical object can include
> information about
> where it will be drawn, in what font, and so on. For example,
> grobWidth(textGrob("foo", gp=gpar(fontfamily="mono", cex=2))) is very
> different from stringWidth("foo"). If you want to determine
> the size
> of some text that you want to draw as part of the panel axis AND you
> want it to look like the text that lattice would have drawn, then
> something like this might give you what you want:
>
> grobWidth(textGrob("your label",
> gp=do.call("gpar",
> trellis.par.get("axis.text"))))
>
> It is also important that you do these calculations within a panel
> function so that they get evaluated within the appropriate context
> (i.e., higher-level lattice graphical parameter settings have been
> enforced). The result of the above call to grobWidth() could be very
> different if evaluated in some other context.
>
> Finally, if you use convertX() (or any of its ilk), be aware that
> changes in the device size (e.g., resize a window) could make the
> calculations invalid. Maybe we could follow this up on the r-devel
> mailing list if you think this will be an issue.
>
> Paul
>
>
> >>Indirectly related, setting outside=TRUE in a panel.axis()
> call does not
> >>produce visible labels, perhaps due to "issues of clipping"
> as mentioned in
> >>its help page. How might one disable clipping for the
> current panel /
> >>viewport?
> >
> >
> > At the grid level, there's a 'clip' argument to
> 'viewport()'. In lattice,
> > these are chosen from
> >
> >
> >>str(trellis.par.get("clip"))
> >
> > List of 2
> > $ panel: chr "on"
> > $ strip: chr "on"
> >
> > (In case you are using 'trellis.focus', that can set clipping off.)
> >
> > Deepayan
> >
> > ______________________________________________
> > R-help@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
>
>
> --
> Dr Paul Murrell
> Department of Statistics
> The University of Auckland
> Private Bag 92019
> Auckland
> New Zealand
> 64 9 3737599 x85392
> paul@stat.auckland.ac.nz
> http://www.stat.auckland.ac.nz/~paul/
>
>

        [[alternative HTML version deleted]]



R-help@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 Received on Fri Jun 03 07:53:59 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:22 EST