my scale_color_gradient displays a rainbow from low=green to high=red but I want this to be mapped to a variable z (that I have) between 0 and 1. The problem is that even if z does not reach 1, I still get the whole rainbow. I want the rainbow to stop at orange for example if z stops at 0.5. Can you help me with that ?
Thanks.
Thanks, that works. Now, the legend displays unused colours. Is there a way to have a legend adapted to the graph ? Below, there is no red on the graph but there is on the legend. I would want it to range from 0 to 75 approximately as you can see. Thanks again.
Actually, I cannot do this. This graph will run on a Shiny app and the parameters that provide this plot will change. So you could imagine graphs with green as the 'maximum' colour. If you tell me this is not possible to have a legend that adapts to the maximum value of my variable z, that's fine.
It seems the function colorRamp(c("green","red")) maps any number between 0 and 1 to a color between green (0) and red (1). So I thought this was possible.
Ok, I finally manage to do so thanks the the function colorRamp2 from the package 'circlize'. I just set as limits min(z) and max(z) and it works just fine. Thanks again. I valid your answer to close this topic.