[R] draw a 5cm x 3cm rectangle

Erik Iverson iverson at biostat.wisc.edu
Thu Oct 16 19:00:06 CEST 2008


I would personally use grid for this.

library(grid)
grid.rect(width = 5, height = 3, default.units = "cm")


Barry Rowlingson wrote:
> 2008/10/16 Thomas Steiner <finbref.2006 at gmail.com>:
>> Hi I want to draw sth in a pdf file with a predefined defined size.
>> Say a 5cm x 3cm rectangle (a ruler):
>>
>> pdf("rect.pdf", paper="a4")
>> plot(c(1,5,5,1,1),c(1,1,3,3,1),asp=1,axes="n")
>> dev.off()
>>
>> but how do I fix that one unit is 1cm?
> 
>  I just did help.search("inch") and found xinch:
> 
>      'xinch' and 'yinch' convert the specified number of inches given
>      as their arguments into the correct units for plotting with
>      graphics functions.  Usually, this only makes sense when normal
>      coordinates are used, i.e., _no_ 'log' scale (see the 'log'
>      argument to 'par').
> 
>  Then help.search("cm") gave me cm:
> 
> Description:
> 
>      Translates from inches to cm (centimeters).
> 
>  You just need the inverse of this. Not too hard.
> 
>  Also, the symbol() function takes an inches=TRUE parameter that lets
> you specify inches as the object size.
> 
>  The grid graphics package has a units system as well, but I've not
> played with that. See help("unit") for info.
> 
> Barry
> 
> ______________________________________________
> 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