How to change the background color of legend in base R plot?



To create the legend for a plot in base R, we can use legend function and if the background color of the legends needs to be changed from white to any other then bg argument in legend function will be used. For example, to change the background color to red then we can use bg="red".

Example1

 Live Demo

plot(1:10)
legend("right",legend="point chart",bg="blue")

Output

Example2

 Live Demo

plot(1:10)
legend("right",legend="point chart",bg="light green")

Output

Example3

 Live Demo

plot(1:10)
legend("left",legend="point chart",bg="light grey")

Output


Advertisements