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

Randall C Johnson [Contr.] rjohnson at ncifcrf.gov
Tue Feb 13 15:58:59 CET 2007


Hello,
I was thinking that was probably the case. I'm creating a series of graphics
that contain smaller graphics, and was trying to reduce the bounding box as
much as possible with out the plotting points bleeding over to the
surrounding features. I could hard code the size of the bounding boxes (or
use a creative calculation), but that would be tedious, not to mention what
would happen if someone decides they would like to change the plotting point
or it's size. ;) The number of predefined types of points available in a
pointsGrob is handy, but I also like the idea of using circles or
polygons...

I might also add that I've just started using the grid graphics system in
the last few months, and I'm impressed at how powerful and flexible it is.

Thanks!
Randy


On 2/12/07 2:27 PM, "Paul Murrell" <p.murrell at auckland.ac.nz> wrote:

> 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.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



More information about the R-help mailing list