[R] ggplot2: using more than 6 symbols

hadley wickham h.wickham at gmail.com
Mon Nov 17 14:00:50 CET 2008


Hi Dave,

On Mon, Nov 17, 2008 at 6:35 AM, Dave Murray-Rust
<d.murray-rust at ed.ac.uk> wrote:
> I'm trying to plot multiple lines using different colours/symbols to
> distinguish them. If I try to plot more than 6 lines, I get an error:
>
>> ggplot( dat, aes(x=time,y=value,group=variable,shape=variable) ) +
>> geom_line()
> Error: scale_shape can deal with a maximum of 6 discrete values, but you
> have 9.  See ?scale_manual for a possible alternative
>
> I find this slightly confusing, as there are ~25 symbols listed for use.
> (I'm using ggplot2 0.7, on OSX, R 2.7.2)

But distinguishing between more than 6 of is very difficult!

> Ideally, I'd like to use a combination of colours and symbols (e.g. 5
> colours and 4 symbols -> 20 unique possibilities) or even colours, symbols
> and linetypes - is there a way to do this in ggplot2?

Unfortunately not - this type of combined scale is on my to do list,
but I haven't got around to it yet.  Here's a work around:

df <- data.frame(a = 1:20, b = 1:20, c = letters[1:20])
qplot(a, b, data = df, colour = c)

df$d <- factor(rep(1:5, each = 4))
df$e <- factor(rep(1:4, by = 5))

qplot(a, b, data = df, colour = d, shape = e)

Generally, I'd wouldn't advise splitting up a single variable across
two aesthetics like this: perceptually I don't think its a great idea.

Regards,

Hadley

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



More information about the R-help mailing list