Faction in the legend, several colors

I need to create a complex legend that includes a fraction, and the numerator and denominator are in different colors Legend .

Is it possible to create such a legend with (base) R?

Since I need to add this legend on several graphs of different graphs, I do not want to manually program the text, but I can add it automatically as a legend. It is not necessary to be a legend (although it would be convenient), however I do not want to manually enter the coordinates of each element.

Any ideas ?!

+6
source share
1 answer

Assuming you have something like:

d=1:10 plot(d,type="l") 

and you don’t need different colors for the numerator and denominator, you can do this with a single line (including text hint at @CarlWitthoft):

 text(0.5*max(d), 0.9*max(d), expression(Result == frac(Green, Blue)), cex=1.5) 

enter image description here

but there is no easy way to change the color of the numerator and denominator. So the clunky way is to configure each item separately:

 text(0.4*max(d), 0.9*max(d), "Result =", cex=1.5) text(0.55*max(d), 0.93*max(d), "Green", col="green", cex=1.5) text(0.55*max(d), 0.87*max(d), "Blue", col="blue", cex=1.5) segments(0.5*max(d), 0.9*max(d), 0.6*max(d), 0.9*max(d)) 

enter image description here

which I know, this is not what you really want, but just in case there will be no better hack ...

+8
source

Source: https://habr.com/ru/post/912703/


All Articles