0

I am trying to color some joyplots a specific set of colors. However, when I use the following code:

ggplot(data=data, aes(x=x, y=y, fill=color))+
    geom_density_ridges(scale=1.5)+
    theme_joy()+
    ylab("")+
    labs(fill="")

where 'color' is a text vector in my data frame, I get output that fills the plots with the automatic colors, not the ones specified in my vector.

When I try to modify the code to manually assign colors values as follows:

ggplot(data=data, aes(x=x, y=y, fill=c("red", "black", "blue")))+
    geom_density_ridges(scale=1.5)+
    theme_joy()+
    ylab("")+
    labs(fill="")

I get the following error: Aesthetics must be either length 1 or the same as the data (103): fill

What is going on here? When I specify that the fill should be the color vector I get automatic colors, and when I try to manually implement the colors I am getting an error that my specification doesn't match the vector length.

How can I get the colors I want? Not sure what I am missing here?

Thanks for any assistance.

seth_d
  • 1
  • 2
    Does this answer your question? [How do I manually set geom\_bar fill color in ggplot](https://stackoverflow.com/questions/18229835/how-do-i-manually-set-geom-bar-fill-color-in-ggplot) – cory May 25 '21 at 18:29
  • 1
    Your use of literals in `fill=` is nonstandard, and may really only work if your `data` actually only has three rows. Even if that's true, that is not the preferred way to do it, you should be using `scale_color_discrete(.)` or `scale_color_manual(.)`. I don't know if you can get much more specific help without sample data. Please consider adapting your code to use a public dataset, perhaps `iris` or `ggplot2::diamonds`. – r2evans May 25 '21 at 18:30
  • Try using `aes(x=x, y=y, fill=color)` and then add ` + scale_fill_identity()`. It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick May 25 '21 at 18:42
  • Hi folks- thanks for the replies. The suggestion to add '+ scale_fill_identity()' solved my issue nicely. – seth_d May 26 '21 at 17:00

0 Answers0