Shade a graph using polygon function
In this method, we are calling the polygon function with its argument col passed with the name or the hex code of the color needed to be shaded in the given graph.
Polygon function:
It is used to plot a polygon between specified points in an existing plot.
Syntax: polygon(x_coordinates, y_coordinates,col)
Parameters :
- x_coordinates, y_coordinates: x, y coordinates of plot to draw polygon
- col: Color to the polygon
Returns: a polygon in a given plotParameters;
Example:
In this example, we will create a random line graph, and then with the use of the polygon function argument col, we will specify the color to green of the created graph.
R
# data x<- c (2,4,4,2) y<- c (2,2,4,4) plot (x, y, type = "l" ) # Polygon polygon (x, y, col = "green" ) |
Output:
How to shade a graph in R?
In this article, we will be looking at the various approaches to shade a graph in the R programming language.