[R] convert lines to inches

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sun Oct 19 11:58:11 CEST 2008


Thomas Steiner wrote:
> Hi,
> 
> how can I convert the unit "lines" of par("mar") into inches?
> par("mai") could help, but does not (see code below).
> 
> I want to plot a curve in a predefined size in pdf (I add some margin
> space to the plot width&height, everything is in cm):
> pdf("test.pdf",width=(20+2+4)/2.54,height=(10+3+1)/2.54)
> plot(10:30, 9*cos(10:30),type="l",xlim=c(10,30),ylim=c(-10,15),xaxs="i",yaxs="i",asp=1)
> #par(mar=c(0,0,0,0))
> par(mai=c(2,3,4,1)/2.54)
> box("figure", col="darkblue")
> dev.off()
> 
> The size of the darkblue box is fine, but I cannot yet control the
> size of the plot area (although
> http://research.stowers-institute.org/efg/R/Graphics/Basics/mar-oma/index.htm
> helped me a lot). And seeting the mar to zero (#) works in a R figure,
> but not in a pdf. Why?
> 
> I already asked ("draw a 5cm x 3cm rectangle") a related question
> three days ago, but I was unable to get a more complicated example in
> the grid package (solution there) running.

Sorry, but I can't make heads or tails of this. You are not stating what 
you intend to achieve, hence there is no way to see what you mean by "is 
fine" or "doesn't work".

You have

 > par("mar")/par("mai")
[1] 5 5 5 5
 > par("csi")
[1] 0.2
 > par("lheight")
[1] 1

which should give you a strong hint about the conversion. Also:

par("pin")+ rev(rowSums(matrix(par("mai"),2))) == par("fin")

(up to rounding error).

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list