ggplot wrong color assignment

As you want to supply color names to argument colour= and display also a legend for this argument, you should add scale_colour_identity() to your last line in function. This scale ensures that values supplied will be interpreted as actual color values. Adding of argument breaks=cols_hex in function scale() will ensure ordering of names in legend.

ggplot(NULL) +     
geom_point(data=data, aes(x=x, y=y, colour=cols_hex), size=size, alpha=alpha) + 
        scale_colour_identity(guide="legend",breaks=cols_hex)

Leave a Comment