Skip to content
Prev 316715 / 398506 Next

Change default order of colors & line types

You can change colors by manually creating your own palette.  You can
start with the Set1 color palette from RColorBrewer, then move the
values.  You then use this new palette in your plot:

library(RColorBrewer)

numGroups <-5 #here is where you define the size of your color palette
customPalette <- brewer.pal(numGroups, "Set1") #create your color palette
customPalette <- append(customPalette, customPalette[1], after=4)
#insert the first color into the correct place on the list
customPalette <- customPalette[2:len(customPalette)] #drop the first color

To use this in your plot, instead of using
scale_color_brewer(palette="Set1"), you would use
scale_color_manual(values=customPalette).

Linetype will need to be handled a slightly different way.  Remove
linetype=method from your initial qplot command, and then add a manual
linetype scale that would look something like this:

+ scale_linetype_manual(breaks=c("m1", "m2", "m3", "m4", "m5"),
values=c(2,3,4,1,5))

where "m1", "m2", etc are the method names that you are grouping
everything by.  You should keep your geom_line() command the same.
Note that the values in scale_linetype_manual() are rearranged to put
1 in the 4th position.  I'm sure there is a more elegant way to do it,
but this way should work as long as you aren't creating lots of plots
with changing method names.


--
Cheers,

Harris Butler
On Fri, Feb 1, 2013 at 1:41 PM, Soyeon Kim <soyeon.sophia.kim at gmail.com> wrote: