Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Setting legend corresponding to end values of graph

$
0
0

I would like to adjust my legend (ggplot2) in such a way that the upper value in the legend corresponds to the highest end value. For example:

Blue line ends on a value of 200, which is the highest, i want the blue color to be the top color in the legend.

When orange line has second biggest endvalue in the graph i want that color to be second in the legend. And so on...

I have tried to do it manually with: scale_color_discrete(labels = c(.....) But still those don't give me the right format.

Is there a way to let R do this for me?

enter image description here

So for this picture i would like to have the legend as follows: - Red - Blue - Green

Since the ending values are in that order.

scale_color_discrete(labels = c("Apple", "Banana", "Pear"))

This code works for setting the order of the legend, but in my own graph the manually labelled items don't correspond with the order in the graph.


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>