Skip to content

two ggplot and colour=x question

3 messages · Rainer M Krug, Hadley Wickham

#
Hi

I am using ggplot with the aesthetic=list(..., colour=x, ...)

ggplot()
ggline()

I have four different values in x ("ren", "cyn", "mixed", "bare") and I 
have two questions

1) I would like to assign specific colours to the values, i.e. green, 
red, blue and brown. How can I do this? I did not understand 
map_colour_brewer.

2) I don't want the legend top be plot. How can I disable the legend to 
be plotted?

Thanks

Rainer
#
There's not really an easy way to do this at the moment.  However, you
can create a new variable containing the colours you want to use and
then use a manual scale so they aren't converted automatically:

df$colour <- c("red","blue","yellow","orange)[df$myvar]
p <- ggplot(data=df, aes=list(x=x,y=y,colour=colour)
scmanual(p, "colour")
If you use a manual scale (as above) there won't be a legend, or more
generally you can do:

p$legend.position <- "none"
to turn of the legend (see ?ggopt for other options)

Hadley
#
Thanks a lot for your help - I'll try it out and let you know if I still 
have problems.

Rainer
hadley wickham wrote: