0

I am trying to implement the viridis package using viridis:: + scale_fill_viridis().

This is my code:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(aes(colour=gender)) + 
xlim(-5,20)  + scale_fill_viridis()

However, this probably interferes with my use of aes(colour=gender), which draws a seperate line for the two genders in my dataset, using 2 different colours of the ggplot2 basic palet.

My question is: How do you use a custom color palette such as viridis, in combination with the aes(colour="variable") argument.

Cheers

Milan Post
  • 43
  • 6
  • 1
    Can you plase share part of your data so we can reproduce your problem? here you can see a useful guide https://stackoverflow.com/questions/49994249/example-of-using-dput – bpvalderrama Jun 11 '22 at 12:41
  • 1
    Although, the most probable thing is that you need to use `scale_color_viridis_d` from the viridisLite package instead of `scale_fill_viridis` – bpvalderrama Jun 11 '22 at 12:47
  • The dataset contains sensitive information. Is it really needed to see the data? – Milan Post Jun 11 '22 at 13:06
  • scale_color_viridis_d also does not change the color palette from the basic ggplot2 palette – Milan Post Jun 11 '22 at 13:07
  • 2
    you can always produce a dataset that looks like the original but with fake data. And yes, it is really helpful to have an actual dataset **to reproduce your error** and try to make things work out. – bpvalderrama Jun 11 '22 at 13:16

1 Answers1

1

So, it's a little difficult to do this without your data. I'm also not entirely sure what, specifically, you're trying to color. I'm assuming it's the gender.

I set a color palette (I like wespalette, so here's a wespalette example, but you could do the same with virdis, getting a vector of specific colors you want to use).

    # load color palette
palette_c <- wes_palette("FantasticFox1", 5)

Then, I pull out the colors I want to use. Rather than the scale_..._virdis, you might want to try the built in functions.

#Add colors
      + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))

Also, might have to move the color outside of the aes, but I'm not sure what the structure of your data is, so your mileage may vary. So, potentially start tinkering with something like:

ggplot(combi_plot, aes(x = day_of_symptoms, y = ct_value)) + geom_smooth(color=gender) + 
xlim(-5,20) + scale_color_manual(values = c("Female" = palette_c[5], "Male" = palette_c[4]))