You can shade and color your graphs using the
polygon() command. To use the
polygon() command, you must specify the horizontal and vertical axis limits, but you must also include the x and y variables as the middle arguments.
Let's create a quadratic curve and shade under it with a light green selected from the Hexadecimal Color Chart:
x <- 1:100 y <- 3*x^2 + 2*x + 7 plot(x, y) lines(x, y) polygon(cbind(c(min(x), x, max(x)), c(min(y), y, min(y))), col="#00CC66")
Here is the graph:
Using this approach, the
polygon() command shades under the curve, between the minimum and maximum values of the x variable and below the ...