Shade the area between two lines
In this method, we are using the polygon function with the col argument within it and here, the difference is just in the shape of the given graph rest all is similar to the previous method.
Example:
In this example, we will be creating two sin function line graphs and between these line graphs, we will be filling the color to green using the polygon function with the col specified to green as the argument.
R
# Grid of X-axis values x <- seq (0, 10, 0.01) # Data y1 <- sin (x) + 8 y2 <- 2* sin (x) + 4 # Lines plot (x, y1, type = "l" , ylim = c (1, 10), ylab = "y" ) lines (x, y2, col = 2) # Fill area between lines polygon ( c (x, rev (x)), c (y2, rev (y1)), col = "darkgreen" ) |
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.
Contact Us