[R] consolidate legends in ggplot2

hadley wickham h.wickham at gmail.com
Thu Feb 7 20:09:59 CET 2008


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','burlywood1',
'cadetblue1','maroon3','aquamarine','bisque1','darkgoldenrod1','darkkhaki',
'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