scale_fill_discrete and scale_fill_manual - legend options confusion

78,009

You do not need to make it double, this should work:

scale_fill_manual(values = c("red", "green", "blue"), name = "My name", 
                  guide = guide_legend(reverse = TRUE))
Share:
78,009
Marta Karas
Author by

Marta Karas

I am a PhD student in Biostatistics at JHU. mkaras2 at jhu.edu

Updated on December 31, 2020

Comments

  • Marta Karas
    Marta Karas over 3 years

    I have a problem with applying two different changes on my ggplot2 object. I have a barplot with 3 groups on it. I want to:

    1. set color for each group
    2. reorder the order of legend labels

    I have found the following solutions to the above problems:

    1. + scale_fill_manual(values = c("red", "green", "blue"))
    2. + scale_fill_discrete(guide = guide_legend(reverse=TRUE))

    The problem is the second application (+ scale_fill_discrete(...)) is overriding the first one:

    Scale for 'fill' is already present. Adding another scale for 'fill', which will replace the existing scale.
    

    (separately both of them work fine). How to deal with it?