How are the size of points created in geom_point

158 views
Skip to first unread message

Brian Weaver

unread,
Mar 25, 2011, 12:33:55 PM3/25/11
to ggplot2
I have been working on an optimum experimental design problem where I am trying to find the proportion of units I should allocate to 4 different factor-level combination of temperature and current.  The following code shows one way that I have been trying to show such an optimum plan:

library(ggplot2)

o.pts <- data.frame(Temp = c(40,93,40,93),Current = c(30,30,40,40),
                    prop = c(0.4873989, 0.1435308, 0.1226544, 0.2464159 ))
p <- ggplot(o.pts,aes(Temp,Current,size = prop))
p + geom_point() + scale_size(name = "Proportion",
                   breaks = sort(c(0.4873989, 0.1435308, 0.1226544, 0.2464159 ),decreasing = T),
                   labels = sort(c(0.487, 0.144, 0.123,0.246),decreasing = T) ) +
                   xlab("Ambient Temperature (Degrees C)") + ylab("Current (milliAmps)")+
                   theme_bw() +
    opts(axis.text.y = theme_text(size = 12,hjust = 1)) +
    opts(axis.title.y = theme_text(size = 15,angle = 90)) +
    opts(axis.text.x = theme_text(size = 12,vjust = 1)) +
    opts(axis.title.x = theme_text(size = 15)) 

where Temp is for temperature, Current is for current, and prop is the proportion of units.  My question is what is the relation between the size of the points plotted and the values of prop set in the aesthetic?  Naively in my write up I was saying that the area of the points is proportional to the proportion allocated but I do not believe this to be true.  Thank you for your help in advance.

Brian

Kohske Takahashi

unread,
Mar 25, 2011, 11:09:31 PM3/25/11
to Brian Weaver, ggplot2
Hi,

geom_point (i.e., pointsGrob in grid package) draw symbols as characters.
And size aes is finally used for fontsize specification (see ?pointsGrob).
So it is hard to say the relation between size value and actual size
of symbols, but probably, in the case of circle symbol, the size
corresponds to the radius.

try this:

d <- data.frame(x=c(1,1,2,2),y=c(1,2,1,2),s=c(1,2,3,4)*10)
ggplot(d, aes(x,y,size=s)) + geom_point() + scale_size_identity() +
xlim(0,3) + ylim(0,3)

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Hadley Wickham

unread,
Mar 29, 2011, 9:52:51 AM3/29/11
to Kohske Takahashi, Brian Weaver, ggplot2
On Fri, Mar 25, 2011 at 10:09 PM, Kohske Takahashi
<takahash...@gmail.com> wrote:
> Hi,
>
> geom_point (i.e., pointsGrob in grid package) draw symbols as characters.
> And size aes is finally used for fontsize specification (see ?pointsGrob).
> So it is hard to say the relation between size value and actual size
> of symbols, but probably, in the case of circle symbol, the size
> corresponds to the radius.

Yes, and if you want radius to be exactly proportional to value, you
need to make sure that both the limits and the size range includes
zero.

Hadley

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages