[R] consolidate legends in ggplot2

Engelmann, Bernd Bernd.Engelmann at amd.com
Fri Feb 8 08:31:14 CET 2008


Hello Hadley,

thanks again. You are right, it normally is not a good thing to fill the
area with so many colours/shapes/linetypes, but in certain cases you
have to do it. We sometimes have more than 30 different pointclouds on a
scatterplot and the plots are still useful. These plots are analysis
workhorses not intended for the presentation of results.

Bernd

-----Original Message-----
From: hadley wickham [mailto:h.wickham at gmail.com] 
Sent: Thursday, February 07, 2008 8:10 PM
To: Engelmann, Bernd
Cc: r-help at r-project.org
Subject: Re: [R] consolidate legends in ggplot2

Hi Bernd,

> Can ggplot2 handle bigger numbers of breaks by reusing aesthetics ?

No - the attributes were fairly careful picked to actually be
distinguishable, which is very hard to do above a certain number of
colours/shapes/linetypes etc.

But your approach (creating your own scales) is basically correct - I
will provide things that I think work best perceptually as defaults, but
it should be easy for you to override them if you believe otherwise.  In
the latest version you can simplify your code to:

my_colour <- scale_colour_manual(values =
c('green','red','blue','violet','orange2','skyblue','magenta','burlywood
1',
'cadetblue1','maroon3','aquamarine','bisque1','darkgoldenrod1','darkkhak
i',
'cornsilk3', 'lightsalmon1','deepskyblue2','goldenrod1','hotpink',
'lightslateblue', 'mistyrose1','olivedrab1','plum1','pink1','orange3'))

and

my_solid_shape <- scale_shape_manual(values = c(16, 17, 15, 3, 7, 8, 16,
17, 15, 3, 7, 8, 16, 17, 15, 3, 7, 8)) my_hollow_shape <-
scale_shape_manual(values =  c(1, 2, 0, 3, 7, 8, 1, 2, 0, 3, 7, 8, 1, 2,
0, 3, 7, 8))

And the next version will actually be smart enough to create the obvious
legend.

Hadley


--
http://had.co.nz/



More information about the R-help mailing list