[R] Trellis devices and pointize
Deepayan Sarkar
deepayan.sarkar at gmail.com
Sat Jun 21 17:35:01 CEST 2014
On Thu, Jun 12, 2014 at 2:31 PM, Patrick Connolly
<p_connolly at slingshot.co.nz> wrote:
> On Mon, 09-Jun-2014 at 08:33AM +0100, Prof Brian Ripley wrote:
>
> |> The issue here is not trellis.device.
> |>
> |> You are using lattice plots (without mentioning lattice), which are
> |> based on package 'grid' and so using the grid sub-system of a
> |> device. That sub-system does not use the 'pointsize' of the device
> |> as its initial font size. So you need to use
> |>
> |> grid::gpar(fontsize = 28)
> |>
> |> If I call that after opening the device I get what I guess you expected.
>
> I don't see it making any difference at all. At one time I supposed that some clever inner
> workings rescaled everything to something more sensible for a plotting
> region that size, but that is not the case.
>
>> trellis.device(device = pdf, file = "Singers.pdf", height = 160/25.4,
> + width = 160/25.4)
>
>> grid::get.gpar()$fontsize
> [1] 12
>> grid::gpar(fontsize = 8)
> $fontsize
> [1] 8
>
>> grid::get.gpar()$fontsize
> [1] 12
>>
>
> Evidently I missed something somewhere. Grid graphics is sometimes a
> bit too subtle for me. I know gpar() doesn't work exactly analogously
> to the way par() works. I can't find any examples in Paul's "R
> Graphics" book or Deepayan's "Lattice" book (but that might just be
> lack of searching skills).
>
> Then I tried putting it in the call to print.trellis:
>
> print(pik, plot.args = grid::gpar(fontsize = 8))
>
> and in the bwplot() call similar to the way I'd done in panel functions
> with an argument called gp but I get no error message or any
> difference in my resulting plot.
>
> I know I can fiddle with trellis.par.get() and trellis.par.set() but
> that's a bit long-winded when it's so simple to do in base graphics.
Unfortunately that's what you will need to do. The font sizes for text
and points are taken from
> trellis.par.get("fontsize")
$points
[1] 8
$text
[1] 12
and these are the hard-coded defaults for all devices.
There was a discussion last year:
https://stat.ethz.ch/pipermail/r-help/2013-June/354749.html
which almost convinced me to effectively change the default to the
device fontsize, but on further thought I changed my mind (and I see
now that I forgot to follow-up on the list to say so). What did change
was that you can now explicitly set
trellis.par.set(fontsize = list(text = NULL))
to make the default come from grid (which in turn takes the default
from the device).
So,
trellis.device(device = pdf, file = "Singers.pdf", height = 160/25.4,
width = 160/25.4, pointsize = 28)
trellis.par.set(fontsize = list(text = NULL)) # new line
pik <- bwplot(voice.part ~ height, data = singer)# pointsize ignored
print(pik)
dev.off()
should give you what you want. And if you want this to be the default
behaviour, set
lattice.options(default.theme = list(fontsize = list(text = NULL)))
in your .Rprofile.
-Deepayan
> TA
>
> |>
> |>
> |> On 09/06/2014 07:54, Patrick Connolly wrote:
> |> >How is the pointsize set in trellis.devices?
> |> >
> |> >>From my reading of the trellis.device help file, I understood that the
> |> >pointsize arg would be referenced to the call to the pdf function.
> |> >
> |> >So I set up a trellis pdf device as so:
> |> >
> |> > trellis.device(device = pdf, file = "Singers.pdf", height = 160/25.4,
> |> > width = 160/25.4, pointsize = 28)
> |> >
> |> >A base R graphics plot works as I'd expected.
> |> >
> |> > plot(1:10, 50:59) # silly plot with huge plotting characters and letters
> |> >
> |> >However, pointsize is ignored in trellis plots;
> |> >
> |> > pik <- bwplot(voice.part ~ height, data = singer)# pointsize ignored
> |> > print(pik)
> |> > dev.off()
> |> >
> |> >There are many trellis cex-type settings, but FWIU they're all
> |> >relative to the default size. My question is: How do I set that
> |> >default?
> |> >
> |> >
> |> >R version 3.0.2 (2013-09-25)
> |> >Platform: i686-pc-linux-gnu (32-bit)
> |> >
> |> >locale:
> |> > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
> |> > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
> |> > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
> |> > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C
> |> > [9] LC_ADDRESS=C LC_TELEPHONE=C
> |> >[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
> |> >
> |> >attached base packages:
> |> >[1] grDevices utils stats graphics methods base
> |> >
> |> >other attached packages:
> |> >[1] RColorBrewer_1.0-5 lattice_0.20-24
> |> >
> |> >loaded via a namespace (and not attached):
> |> >[1] grid_3.0.2 plyr_1.8 tools_3.0.2
> |> >
> |> >I've tried with R-3.1.0 on another machine so I don't think the
> |> >problem is with an old version.
> |> >
> |> >I doubt it has much to do with pdf specifically. Attempts to use png,
> |> >bitmap, postscript devices all produce equivalent results.
> |> >
> |> >
> |> >
> |> >(Here's all the example code uninterrupted:)
> |> >
> |> > trellis.device(device = pdf, file = "Singers.pdf", height = 160/25.4,
> |> > width = 160/25.4, pointsize = 28)
> |> > plot(1:10, 50:59) # silly plot with huge plotting characters and letters
> |> > pik <- bwplot(voice.part ~ height, data = singer)# pointsize ignored
> |> > print(pik)
> |> > dev.off()
> |> >
> |> >
> |> >TIA
> |> >
> |> >
> |>
> |>
> |> --
> |> Brian D. Ripley, ripley at stats.ox.ac.uk
> |> Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/
> |> University of Oxford, Tel: +44 1865 272861 (self)
> |> 1 South Parks Road, +44 1865 272866 (PA)
> |> Oxford OX1 3TG, UK Fax: +44 1865 272595
>
> --
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
> ___ Patrick Connolly
> {~._.~} Great minds discuss ideas
> _( Y )_ Average minds discuss events
> (:_~*~_:) Small minds discuss people
> (_)-(_) ..... Eleanor Roosevelt
>
> ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list