0

I use ggplot2 to make 10 lines and the color of those lines should be continuously changing, i.e. the color changes from light blue to dark blue. But I want the legend to be discrete.

The code is:

colnames(prop_combined) <- c('Q1', 'Q2', 'Q3', 'Q4', 'Q5', 'Q6', 'Q7', 'Q8', 'Qinf', 'Qhyb')
prop_combined_gg <- melt(prop_combined)
ggplot(data = prop_combined_gg, aes(x = Var1, y = value, group = Var2, color = Var2)) + 
  geom_line() + 
  geom_point() +
  xlab(TeX("$tau$")) + 
  ylab("Power") + 
  labs(color=TeX("$\\gamma$")) 

The output image looks like this: enter image description here

Update: I want the image looks like:

enter image description here

But instead, the label should not be continuous

tjebo
  • 21,977
  • 7
  • 58
  • 94
Simon
  • 15
  • 4
  • But you can only have one colour per line, so how can the colour change be continuous? Do you mean you want the change to be all shades of the same colour? – Allan Cameron Mar 15 '22 at 21:02
  • `color=value` ? And maybe with `linetype=Var2`. As put by @AllanCameron, hard to know what the expected output is. – Baraliuh Mar 15 '22 at 23:37
  • sounds very much like https://stackoverflow.com/questions/50506832/create-discrete-color-bar-with-varying-interval-widths-and-no-spacing-between-le?noredirect=1&lq=1 or https://stackoverflow.com/questions/30352412/how-do-you-create-a-gradient-of-colors-for-a-discrete-variable-in-ggplot2?noredirect=1&lq=1 – tjebo Mar 16 '22 at 15:29
  • If those links are indeed about what you're after, please kindly consider closing your question as a duplicate - or let me know, and I'll do this for you – tjebo Mar 16 '22 at 15:29
  • thanks for clarifying - check this answer, it shows how to get your desired legend. https://stackoverflow.com/a/30352871/7941188 – tjebo Mar 16 '22 at 21:30

0 Answers0