plot mean of points at a single location

403 views
Skip to first unread message

Matt Pocernich

unread,
Sep 5, 2012, 1:37:16 PM9/5/12
to ggp...@googlegroups.com
Hi,

I believe this to be an easy question, but I am stumped.

I have multiple measurements at set of locations. Without preprocessing it using plyr or aggregate, how would I set color or size to reflect the mean?

For example,

temp <- data.frame( x = rep(1:3, each = 3), y = rep(1:3, each = 3), value = rnorm(9))

p <- ggplot(aes(x = x, y = y), data = temp)

## for each point, I would like to have the color or size represent the mean - or some other statistic.

p + geom_point(aes(col = mean) )



Thanks,

Matt

Ben Bond-Lamberty

unread,
Sep 5, 2012, 1:47:37 PM9/5/12
to Matt Pocernich, ggp...@googlegroups.com
Try

p+geom_point(aes(color=value,stat="summary",fun.y="mean"))

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

Matt Pocernich

unread,
Sep 5, 2012, 2:04:47 PM9/5/12
to bpb...@gmail.com, ggp...@googlegroups.com

Thanks.

I believe that is what I need.  I saw that in the documentation, but the argument fun.y confused me.  The ".y" caused me to assume that the function would be applied to the y value. 

How would I extend this example to set the point size equal to the max value at each x,y location?

Thanks again,

Matt


> Date: Wed, 5 Sep 2012 13:47:37 -0400
> Subject: Re: plot mean of points at a single location
> From: bpb...@gmail.com
> To: matt_po...@hotmail.com
> CC: ggp...@googlegroups.com

Ito, Kaori (Groton)

unread,
Sep 5, 2012, 2:05:45 PM9/5/12
to Ben Bond-Lamberty, Matt Pocernich, ggp...@googlegroups.com
I guess you may want to do something like this? (I changed y=y to y=value)

ggplot(aes(x = x, y = value), data = temp) +
geom_point() +
stat_summary(fun.y=mean, geom="point", shape=18, size=5, col="red")

Kaori
-----Original Message-----
From: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] On Behalf Of Ben Bond-Lamberty
Sent: Wednesday, September 05, 2012 1:48 PM
To: Matt Pocernich
Cc: ggp...@googlegroups.com
Subject: Re: plot mean of points at a single location

Ben Bond-Lamberty

unread,
Sep 5, 2012, 2:29:58 PM9/5/12
to Matt Pocernich, ggp...@googlegroups.com
This works too, and is less confusing notationally:

p+geom_point(aes(color=value,stat="summary",fun="mean"))

Re your question, I think just

p+geom_point(aes(size=value,stat="summary",fun="max"))

Ben


On Wed, Sep 5, 2012 at 2:04 PM, Matt Pocernich
Reply all
Reply to author
Forward
0 new messages