Search code examples
rarea

Shaded area in R only with point in axis Y


For example I have just the data for Y:

55.64
79.21
47.8
28.52
43.99
83.02
87.04
85.44

But I'd like to plot a shaded area with that data, is that possible?


Solution

  • I'm not sure about what you want to achieve but here is a way to color the area under the line defined by Y (assuming the corresponding x values are 1 to length(Y)), either with plain color or with shading lines:

    par(mfrow=c(1, 2))
    # plain color (grey)
    plot(seq(Y), Y, type="l", main="plain color")
    polygon(c(1, seq(Y), length(Y)), c(0, Y, 0), col="grey")
    # shading lines
    plot(seq(Y), Y, type="l", main="shading lines")
    polygon(c(1, seq(Y), length(Y)), c(0, Y, 0), density=10)
    

    enter image description here