[R] Width of a plotting point (in inches) in grid package

Paul Murrell p.murrell at auckland.ac.nz
Mon Feb 12 20:27:06 CET 2007


Hi


Randall C Johnson [Contr.] wrote:
> Hello,
> I'm trying to determine the width of a plotting point (in inches) in the
> grid package. I naively thought I could create a pointsGrob with only one
> point and get the width (as tried below), but this results in an object with
> a size of 0inches (changing cex has no effect). Does anyone have a better
> approach? Of course, it would be dependent upon the graphics parameters and
> viewport...


The width of a pointsGrob is based on a bounding box surrounding all of
the (x, y) locations at which the points are located.  It takes no
notice of the size of the symbol drawn at the locations.  With one
point, the bounding box has zero size.  The wisdom of this design could
be debated ...

What do you need the symbol width for?  Could you use a circle,
rectangle, or polygon instead (all of which calculate their width based
on the bounding box of the shape that is drawn)?

Paul


> Thanks,
> Randy
> 
>> library(grid)
> 
>> pushViewport(viewport())
> 
>> convertX(grobWidth(pointsGrob(1, 1)), 'inches')
> [1] 0inches
> 
> # I think we're measuring the size of the point here...
> # changing cex has no effect.
>> convertX(grobWidth(pointsGrob(1, 1, gp = gpar(cex = 3))), 'inches')
> [1] 0inches
> 
> # If I add a second point, the size should increase...
> # how big is the plotting point though???
>> convertX(grobWidth(pointsGrob(1:2, 1:2)), 'inches')
> [1] 11.1929133858268inches
> 
>> sessionInfo()
> R version 2.4.1 (2006-12-18)
> i386-apple-darwin8.8.2
> 
> locale:
> C
> 
> attached base packages:
> [1] "grid"      "stats"     "graphics"  "grDevices" "utils"     "datasets"
> [7] "methods"   "base"
> 
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Randall C Johnson
> Bioinformatics Analyst
> SAIC-Frederick, Inc (Contractor)
> Laboratory of Genomic Diversity
> NCI-Frederick, P.O. Box B
> Bldg 560, Rm 11-85
> Frederick, MD 21702
> Phone: (301) 846-1304
> Fax: (301) 846-1686
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/



More information about the R-help mailing list