[R] Alternative to cxy in R
Martin Maechler
maechler at stat.math.ethz.ch
Wed Jan 5 12:40:41 CET 2000
>>>>> "BDR" == Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:
BDR> On Wed, 5 Jan 2000, [iso-8859-1] Jesús María Frías Celayeta wrote:
>> good morning to the R-help list!,
>>
>> I would like to ask if there is an alternative to the S ploting
>> parameter "cxy" in R. I am trying to port some S code to R that makes use
>> of this "cxy" parameter to scale the graphics, and I don't find this
>> parameter in help(par).
BDR> R has cin, which gives this in inches, and pin and usr will enable
BDR> you to convert these to user coordinates (I think those are the
BDR> right ones).
BDR> You can usually make use of csi, for example yinch(par("csi")) is a
BDR> reasonable replacement for par("cxy")[2], and by use of cra you
BDR> can rescale to the width.
Last time this was a topic on R-help, your answer was a bit more
elaborated:
>> From: Prof Brian D Ripley <ripley at stats.ox.ac.uk>
>> Sender: owner-r-help at stat.math.ethz.ch
>> To: John Maindonald <john.maindonald at anu.edu.au>
>> cc: r-help at stat.math.ethz.ch
>> Subject: Re: [R] Character height & width in user co-ordinates
>> Date: Mon, 17 May 1999 07:49:29 +0100 (BST)
>>
>> On Mon, 17 May 1999, John Maindonald wrote:
>>
>> > Is there an equivalent to the S-PLUS par()$cxy in R?
>>
>> That is specified as giving:
>>
>> cxy=c(x1,y1) character size (width and height) in usr coordinates.
>>
>> When I needed this (V&R2, p.74) I used for the height yinch(par("csi")).
>> The width is a lot less clearcut, since R (and indeed S-PLUS) allows
>> variable-width fonts. I would use strwidth() to find the actual width.
>> There is also strheight(), but I think that computes the actual
>> height rather than the nominal height given by par("cxy").
>>
>> I think that (0.57*xinch(par("csi")), yinch(par("csi"))) is a reasonable
>> substitute, 0.57 coming from some experiments I did when I first
>> encountered this.
In the mean time, the font width/height settings have undergone a few
patches; but I don't know how much your proposal above would be affected.
But anyway: I think par.Rd (i.e. help(par) )
should contain something like the above information.
Alternatively, we could introduce par("cxy") (as "read_only") into R,
which would solve porting problems,
but as you said we should tell users, rather to use strwidth() instead.
By the way, the following script is somewhat revealing:
plot(1)##-- using x11() {default fonts, ...}
chs <- c(strsplit(" .,;:!'`|#@$%^&*()-_=+/\\<>",NULL)[[1]],
letters,LETTERS, paste(0:9))
chs <- chs[chs != ""]# fix bug in R 0.99 (unreleased)
wh <- t(sapply(chs, function(s)c(w = strwidth(s),h = strheight(s))))
apply(round(10000 * wh,2), 2, table)
##- $w
##- 60.02 80.03 100.04 120.04 140.05 160.06 180.07 200.07 220.08 240.09
##- 13 7 1 5 34 9 13 2 3 1
##- $h
##- 201.45
##- 88
summary(10000 * wh[,"w"])
##- Min. 1st Qu. Median Mean 3rd Qu. Max.
##- 60.02 120.00 140.10 135.10 160.10 240.10
round(10000* wh[,"w"])
##- . , ; : ! ' ` | # @ $ % ^ & * (
##- 80 60 80 60 60 60 60 60 60 140 240 140 220 120 180 100 80
##- ) - _ = + / \\ < > a b c d e f g h
##- 80 160 140 140 140 80 80 140 140 140 140 140 140 140 60 140 140
##- i j k l m n o p q r s t u v w x y
##- 60 60 120 60 180 140 140 140 140 80 120 60 140 140 180 120 140
##- z A B C D E F G H I J K L M N O P
##- 120 180 160 180 180 160 160 180 180 60 140 160 140 220 180 200 160
##- Q R S T U V W X Y Z 0 1 2 3 4 5 6
##- 200 160 160 140 160 180 220 180 180 180 140 140 140 140 140 140 140
##- 7 8 9
##- 140 140 140
10000* xyinch(par("csi")) #---- CONSIDERABLY larger (also for y !)
## 300.6317 335.7513
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list