Re: [R] sizing non-vector point shapes in ggplot2

From: Paul Murrell <p.murrell_at_auckland.ac.nz>
Date: Tue, 17 Jun 2008 08:32:51 +1200

Hi

hadley wickham wrote:

> On Mon, Jun 16, 2008 at 7:52 AM, mfrumin <michael_at_frumin.net> wrote:

>> Dear all,
>>
>> With normal plotting, one can size a set of points in a plot using a vector
>> argument to cex in the points() function. This works whether you are using
>> one of the standard R symbols (i.e. 19+) or some ascii symbol, such as '/'
>>
>> eg:
>> plot(1:10, 1:10, type='n');
>> points(1:10, 1:10, cex = 1:10, pch = '/')
>>
>> Trying to make the transition to ggplot2, I find that the aesthetic size
>> mapping does not apply if i do geom_point(..., shape='/') -- the points show
>> up looking like '/' but they are not sized. Is there anything to do about
>> this?
>>
>> eg:
>> ggplot(data = data.frame(x = 1:10, y = 1:10, size = 1:10), aes(x = x, y =
>> y)) + geom_point(mapping = aes(size = size), shape = '/')
>>
>> the plot that I'm making really needs a vertically oriented mark, not a
>> round-ish point/square/triangle that takes up a lot of area. am I totally
>> out of luck?
> 
> Hmmm, I'd never noticed this "feature" of grid before.  To size the
> points, I'm using the size argument of grid.points, which doesn't seem
> to affect the size of character based plotting symbols (because the
> are using the fontsize graphical parameter).  I've cc'd Paul on this
> email so he can confirm whether this is a bug or by design.


Looks like a bug to me. There are difficulties with attempting to make text a specific size because the "point size" of a font is a very rough guideline, however, we should be able to do something a little better than totally ignoring the 'size' argument :)

Paul

> Regardless, you can make ggplot size the symbols correctly by running
> the following code:
> 
> GeomPoint$draw <- function(., data, scales, coordinates, ...) {
>     with(coordinates$transform(data),
>       ggname(.$my_name(), pointsGrob(x, y, size=unit(size, "mm"), pch=shape,
>       gp=gpar(col=colour, fill = fill, fontsize = size * .pt)))
>     )
>   }
> 
> Hadley
> 

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

______________________________________________
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.
Received on Mon 16 Jun 2008 - 23:44:19 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 17 Jun 2008 - 00:30:59 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive