How to change the background color of a plot created by using plot function in R?

R ProgrammingServer Side ProgrammingProgramming

To change the focus of a plot we can do multiple things and one such thing is changing the background of the plot. If the background color of a plot is different than white then obviously it will get attention of the readers because this is unusual as most of the times the plots have white backgrounds, hence if we want to attract readers on the plot then we might use this technique. It can be done by using par(bg= "color_name").

Example

Creating a simple histogram −

 Live Demo

> x<-rnorm(100)
> hist(x)

Output

Example

Creating histogram with different background colors −

> par(bg="green")
> hist(x)

Output

> par(bg="yellow")
> hist(x)

Output

par(bg="blue")
> hist(x)

Output

raja
Published on 04-Sep-2020 07:38:10
Advertisements