stat_sum confusions

52 views
Skip to first unread message

Ben Bolker

unread,
Jan 31, 2012, 11:43:39 AM1/31/12
to ggplot2

Me again.

Still using ggplot 0.9.0. I would try reverting to ggplot 0.8.9 to
see if these are new bugs or if I'm just doing something boneheaded, but
it seems like too much of a nuisance (sorry). Perhaps someone can
confirm whether these work in 0.8.9.

Two issues:

(1) stat_sum() seems to ignore the colour aesthetic ... ?
(2) when I facet_grid I seem to lose the desired behavio(u)r of
stat_sum. This is probably something silly, but I have tried
experimenting with setting the group aesthetic manually and don't seem
to have found a combination that works.

set.seed(101)
d <- data.frame(x=sample(1:5,size=500,replace=TRUE),
y=sample(1:5,size=500,replace=TRUE),
g=sample(c("a","b"),size=500,replace=TRUE))

## creates coloured points
ggplot(d,aes(x,y,colour=g))+geom_point()+facet_grid(.~g)

## no colour -- also no distinctive sizes
ggplot(d,aes(x,y,colour=g))+
stat_sum(aes(group=interaction(x,y,g)))+facet_grid(.~g)

## this works as expected (no colour, different sizes)
ggplot(d,aes(x=x,y=y))+stat_sum()


## aiming for something that looks like this:
library(reshape2)
mm <- melt(with(d,table(x,y,g)))
ggplot(mm,aes(x=x,y=y,colour=g))+geom_point(aes(size=value))+
facet_grid(.~g)


thanks
Ben Bolker

Brandon Hurr

unread,
Jan 31, 2012, 11:58:07 AM1/31/12
to Ben Bolker, ggplot2
I meant plot 2, changing your interaction to 1 seems to get what you want (color and size). 

On Tue, Jan 31, 2012 at 16:56, Brandon Hurr <brando...@gmail.com> wrote:
Ben, 

I can confirm some of the behavior. Plot 3 does have color, but is not different in size on 0.89.

Changing group to 1 in that same plot seems to get what you're looking for in 0.89. 

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reshape2_1.2.1    ggplot2_0.8.9     proto_0.3-9.2     reshape_0.8.4     plyr_1.7.1       
 [6] pcaMethods_1.40.0 Rcpp_0.9.9        pls_2.3-0         MASS_7.3-16       Biobase_2.14.0   

loaded via a namespace (and not attached):
[1] digest_0.5.1 stringr_0.6  tools_2.14.1

Brandon Hurr

unread,
Jan 31, 2012, 11:56:04 AM1/31/12
to Ben Bolker, ggplot2
Ben, 

I can confirm some of the behavior. Plot 3 does have color, but is not different in size on 0.89.

Changing group to 1 in that same plot seems to get what you're looking for in 0.89. 

> sessionInfo()
R version 2.14.1 (2011-12-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reshape2_1.2.1    ggplot2_0.8.9     proto_0.3-9.2     reshape_0.8.4     plyr_1.7.1       
 [6] pcaMethods_1.40.0 Rcpp_0.9.9        pls_2.3-0         MASS_7.3-16       Biobase_2.14.0   

loaded via a namespace (and not attached):
[1] digest_0.5.1 stringr_0.6  tools_2.14.1

On Tue, Jan 31, 2012 at 16:43, Ben Bolker <bbo...@gmail.com> wrote:
group1test.png
plot1.png
plot2.png
plot3.png
plot4.png

Ben Bolker

unread,
Jan 31, 2012, 12:04:45 PM1/31/12
to Brandon Hurr, ggplot2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 12-01-31 11:58 AM, Brandon Hurr wrote:
> I meant plot 2, changing your interaction to 1 seems to get what you want
> (color and size).

Hmm, if you mean

ggplot(d,aes(x,y,colour=g))+
stat_sum(aes(group=1))+facet_grid(.~g)

then that doesn't appear to work in 0.9.0 either ...

thanks
Ben

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJPKB8tAAoJED2whTVMEyK9GNwH/ijMXowxhxq0rhY8DnVdBAqs
bzSwcHxtBXa6yp7hVlrHtWjNB1OnP/dpRrRqcEWGNf1ODkFus1gajJbY3JOP+prQ
G5ShNFZ7g0nf3GpPAVn3hdm3lqp0MjMc0pHoOZRaNXDGTCg/YyI01dXoFOw3vUmM
AzwvQGMemXuR6keFbNmpTPA1utNkEZdb/58ruGepJRu8M6Sj5Kd4T/+K/RRpLCPC
5ZsQoUMzPJgB9EuazTLMtIYSKmkEiCpBkJWNAljNTVjNX+hUNuWv5yV0g/F8kj6E
2VowwbTM/EkPoOqcaPtwGWhiqWdcHnxHtcdDEDF45IjV7jmAkgSqWjyBYQjEh2k=
=fhdw
-----END PGP SIGNATURE-----

Brandon Hurr

unread,
Jan 31, 2012, 12:07:28 PM1/31/12
to Ben Bolker, ggplot2
I wish I knew why, but I don't. :(

Kohske Takahashi

unread,
Jan 31, 2012, 12:20:26 PM1/31/12
to Brandon Hurr, Ben Bolker, ggplot2
Hi, perhaps this is a bug in the new facet_grid, since it works with facet_wrap.

2012/2/1 Brandon Hurr <brando...@gmail.com>:

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

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

Ben Bolker

unread,
Jan 31, 2012, 12:33:59 PM1/31/12
to Kohske Takahashi, Brandon Hurr, ggplot2
On 12-01-31 12:20 PM, Kohske Takahashi wrote:
> Hi, perhaps this is a bug in the new facet_grid, since it works with facet_wrap.
>

I get variable sizes, but not colours, in 0.9.0 with stat_sum() and
facet_wrap():

ggplot(d,aes(x,y,colour=g))+
stat_sum()+facet_wrap(~g)

test6.png

Rainer Hurling

unread,
Jan 31, 2012, 12:36:50 PM1/31/12
to Ben Bolker, ggplot2

Maybe I am missing something here. But mm looks like this

str(mm)
'data.frame': 50 obs. of 4 variables:
$ value: Factor w/ 5 levels "1","2","3","4",..: 1 2 3 4 5 1 2 3 4 5 ...
$ NA : Factor w/ 5 levels "1","2","3","4",..: 1 1 1 1 1 2 2 2 2 2 ...
$ NA : Factor w/ 2 levels "a","b": 1 1 1 1 1 1 1 1 1 1 ...
$ NA : int 8 10 7 14 15 8 15 11 9 7 ...

Don't we need variable names for this example?

>
>
> thanks
> Ben Bolker
>
>
>

Kohske Takahashi

unread,
Jan 31, 2012, 12:41:11 PM1/31/12
to Ben Bolker, Brandon Hurr, ggplot2
Ah, yes.

this works,
ggplot(d,aes(x,y,colour=..n..))+stat_sum()+facet_wrap(~g)

but this does not
ggplot(d,aes(x,y,colour=g))+stat_sum()+facet_wrap(~g)

2012/2/1 Ben Bolker <bbo...@gmail.com>:

--

Dennis Murphy

unread,
Jan 31, 2012, 12:52:15 PM1/31/12
to Ben Bolker, ggplot2
I think Rainer's onto something :)

mm <- as.data.frame(with(d,table(x,y,g)))
ggplot(mm,aes(x=x,y=y,colour=g))+geom_point(aes(size=Freq))+
facet_grid(.~g)

produces the attachment in 0.9.0.

Dennis

bbex.pdf

Ben Bolker

unread,
Jan 31, 2012, 12:55:27 PM1/31/12
to Dennis Murphy, ggplot2
On 12-01-31 12:52 PM, Dennis Murphy wrote:
> I think Rainer's onto something :)
>
> mm <- as.data.frame(with(d,table(x,y,g)))
> ggplot(mm,aes(x=x,y=y,colour=g))+geom_point(aes(size=Freq))+
> facet_grid(.~g)
>
> produces the attachment in 0.9.0.

I don't know what I was dong (reshape 0.8.4, reshape2 1.2.1), but I
wasn't having any trouble getting the melted table with the correct
variable names.

And I don't want to have to create tables and melt manually -- I just
want to be able to use stat_sum() with colour ... (yes, I am aware that
I can get a refund of all the money I have spent on my new copy of
ggplot2 0.9.0 if I'm not satisfied ...)

cheers
Ben

Kohske Takahashi

unread,
Jan 31, 2012, 1:02:27 PM1/31/12
to Ben Bolker, Dennis Murphy, ggplot2
Probably the problem will be fixed.

https://github.com/hadley/ggplot2/pull/382


2012/2/1 Ben Bolker <bbo...@gmail.com>:

--

Rainer Hurling

unread,
Jan 31, 2012, 1:11:10 PM1/31/12
to Kohske Takahashi, Ben Bolker, Dennis Murphy, ggplot2
On 31.01.2012 19:02 (UTC+1), Kohske Takahashi wrote:
> Probably the problem will be fixed.
>
> https://github.com/hadley/ggplot2/pull/382

Wow, great.

And thanks, Dennis. Yes, I had some problem to reproduce the last
example. But of course Ben is right, solving this inside is what we want ;-)

Rainer

Reply all
Reply to author
Forward
0 new messages