[R] font size in graphs...can R read Windows settings?

Dalthorp, Daniel ddalthorp at usgs.gov
Fri Jul 29 03:49:29 CEST 2016


The trouble is getting the figs to look right for different users who
happen to have different display settings. Nearly all my users will be on
MS Windows, and, for the parameter set you gave, the figs will look
different, depending on which "display size" parameter value is active and
the screen resolution (for Windows 7 --- Control Panel | Appearance and
Personalization | Display | Make text and other items larger or smaller).

For example, the following gives different look (for text(), mtext(), axis
labels, etc.) "smaller" than for "larger" or for fine resolution vs. coarse
resolution. Getting it wrong makes the figs look sloppy and hard to read.
If I knew users' display parameters ahead of time, I could adjust the
drawing algorithms using par parameters, but I don't know the display
parameters. 'din' values at time of package attachment (and after closing
of open devices) gives a reasonable proxy in a lot of cases but not always.

par(mfrow = c(1,1),
     las = 1,
     mai = c(0.85, 0.85, 0.32, 0.12),
     font.main = 1,
     cex.main = 1.0,
     cex.lab  = 1.0,
     cex.axis = 0.9)
plot(0,0)
plot(0,0, type='n')
text(0,0, 'junk')
mtext(side = 3, line = .5, "more junk")


On Thu, Jul 28, 2016 at 6:15 PM, Duncan Mackay <dulcalma at bigpond.com> wrote:

> Hi Dan
>
>
>
> This is one of  the features/problems of proportional graphing – getting
> it exactly right.
>
>
>
> Anyway good graphs usually take time
>
>
>
> I wonder if aspect in both base and lattice may be of use.
>
> Also I have a default par settings for base graphics where I sometimes
> change the mai command for multiple graphs and rarely the font size.
>
>
>
> par(mfrow = c(1,1),
>
>     las = 1,
>
>     mai = c(0.85, 0.85, 0.32, 0.12),
>
>     font.main = 1,
>
>     cex.main = 1.0,
>
>     cex.lab  = 1.0,
>
>     cex.axis = 0.9)
>
>
>
> Duncan
>
>
>
> *From:* Dalthorp, Daniel [mailto:ddalthorp at usgs.gov]
> *Sent:* Friday, 29 July 2016 09:22
> *To:* Duncan Mackay
> *Cc:* R
> *Subject:* Re: [R] font size in graphs...can R read Windows settings?
>
>
>
> Thanks, Duncan. This is close to what I was looking for. But I'm not using
> lattice. And the fontsize$text and fontsize$points are independent of
> display settings in Windows (screen resolution and 'size of objects').
>
>
>
> I need to make my graphs [esp. placement and size of text(), mtext()] look
> good regardless of display settings.
>
>
>
> Here's what I'm working with at the moment...
>
>
>
> When package is loaded, I store the default graph size ('din') which is
> correlated with OS display parameters. Then, I simply multiple my current
> 'cex' values by the stored 'din' divided by 7 (which is the 'din'
> associated with the display parameters that I created the figs in
> initially). It seems to work just fine for my text() and mtext() text
> sizes.
>
>
>
> But some of my algorithms for placing text and subfigs in margins still
> need fixing...combinations of 'plt' and 'usr' seem to be working, but it's
> tedious.
>
>
>
> -Dan
>
>
>
> On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay <dulcalma at bigpond.com>
> wrote:
>
> Hi  Dan
>
> For devices png, pdf, postscript and ? others the pointsize argument
> controls the font size which is modified by cex
>
> For lattice there are the settings in trellis.par.get()
>
> trellis.par.get()$fontsize
> $text
> [1] 12
>
> $points
> [1] 8
>
> which you can set and there is no real need to change font size except if
> you need to change main.
> trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
> text
>
> these could be set globally by trellis.par.set() or individually with
> argument par.settings eg
> xyplot(y ~ x, data = datm,
>              par.settings = list(strip.background = list(col =
> "transparent"),
>                                                  fontsize = list(text = 16,
>
> points = 12),  # large size;  need to refine
>                                                 superpose.polygon= list(col
> = c("red","blue"),
>
> border = c("red","blue"))),
>             type = "b")
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mackay at northnet.com.au
>
> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Dalthorp,
> Daniel
> Sent: Thursday, 28 July 2016 07:02
> To: r-help at R-project.org (r-help at r-project.org)
> Subject: [R] font size in graphs...can R read Windows settings?
>
> Hi All,
> I am putting together a package that (among other things) draws some nice
> graphs for users. I place some explanatory text on figs using "text" and
> "mtext". But the size of the text depends on the Windows display settings:
> Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
> panel | Appearance and personalization | Display | Make text and other
> items smaller or larger). If I create figs that look good with one setting,
> the text is too big (or too small) if another setting is used in Windows.
> If I know the Windows setting, I can use cex in R to make the right sized
> labels, but if I don't know a user's Windows display size setting...is
> there a way for R to read the setting? Or is there another way to control
> label size so that text labels on graphs look good regardless of WIndows
> display size setting?
>
> Many thanks for Ideas,
>
> -Dan
> --
> Dan Dalthorp, PhD
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalthorp at usgs.gov
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
>
>
>
>
> --
>
> Dan Dalthorp, PhD
>
> USGS Forest and Rangeland Ecosystem Science Center
> Forest Sciences Lab, Rm 189
> 3200 SW Jefferson Way
> Corvallis, OR 97331
> ph: 541-750-0953
> ddalthorp at usgs.gov
>



-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalthorp at usgs.gov

	[[alternative HTML version deleted]]



More information about the R-help mailing list