How to create a graph in base R with multiple shades of a particular color?


To create a graph in base R with multiple shades of a particular color, we can follow the below steps −

  • First of all, create color shades using colorRampPalette then plot a graph.
  • Use the color shades to create the graph.

Example 1

Create the color shades

Using colorRampPalette function to create the color shades between red and darkred color then creating the plot −

 Live Demo

Color<-colorRampPalette(c("red","darkred"))
plot(1:5,col=Color(5),pch=16,cex=2)

On executing, the above script generates the below output(this output will vary on your system due to randomization) −

Output

Example 2

Create the color shades

Using colorRampPalette function to create the color shades between blue and darkblue color then creating the plot −

 Live Demo

Color<-colorRampPalette(c("blue","darkblue"))
plot(1:8,col=Color(8),pch=16,cex=2)

Output

Updated on: 10-Aug-2021

37 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements