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

R ProgrammingServer Side ProgrammingProgramming

#### Artificial Intelligence : The Future Of Programming

15 Lectures 54 mins

#### Beyond Basic Programming - Intermediate Python

Most Popular

36 Lectures 3 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

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")

## Example2

Live Demo

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

## Example3

Live Demo

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

## Output

Updated on 05-Feb-2021 08:52:12