Adjusting the alpha levels of data points when scale_colour_manual is called

56 views
Skip to first unread message

GregHarhay

unread,
Apr 13, 2009, 3:05:28 PM4/13/09
to ggplot2
Hi:
I'm trying to plot data (in the x-y plane) associated with 9
different classes of data, with each class having its own color.
Normally, I would use scale_colour_brewer( ) + scale_color_hue(alpha
= X ) to change the alpha level of the points. This approach has
worked great before. However, with my current data set I get an error
message stating:

"Error: scale_brewer can deal with a maximum of 8 discrete values, but
you have 9. See ?scale_manual for a possible alternative "

==== Aside ====
I can get a plot to appear if scale_colour_brewer( ) has an argument
or arguments, but I cannot change the color palettes as in
scale_colour_brewer(type="seq", palette=3) with my 9 class data set.
There is no error message generated though. As a matter of fact, it
really doesn't matter what is used as an argument in between the
parentheses for scale_colour_brewer(type="seq", palette=3) or
scale_colour_brewer(type="qualitative", palette=1), the plot remains
unchanged.
==============

Given the error message generated, above, I successfully assigned the
colors of the classes that I desired using :

scale_colour_manual(values = c
("magenta","pink","brown","yellow","orange","purple","green","blue","red"))

My question is: How do I change the alpha levels of these points when
using scale_colour_manual( ) ?

Thanks,
Greg

Mike Lawrence

unread,
Apr 13, 2009, 3:48:08 PM4/13/09
to GregHarhay, ggplot2
a=data.frame(x=1:9,y=1:9,z=factor(1:9))

ggplot(a,aes(x=x,y=y,colour=z))+geom_point()+
scale_colour_manual(values =
I(alpha(c("magenta","pink","brown","yellow","orange","purple","green","blue","red"),.2)))

The I() might not be necessary, I simply saw it used in a previous post.
--
Mike Lawrence
Graduate Student
Department of Psychology
Dalhousie University

Looking to arrange a meeting? Check my public calendar:
http://tr.im/mikes_public_calendar

~ Certainty is folly... I think. ~

GregHarhay

unread,
Apr 13, 2009, 3:57:15 PM4/13/09
to ggplot2
Hi Mike:

Fantastic. That worked!

Thanks,
Greg
Reply all
Reply to author
Forward
0 new messages