1

Hi I am trying to color under the line above 25 on the x axis and it either not showing anything or giving me error, x and y are different length any help would be great Thanks Rob

enter image description here

YetAnotherBot
  • 1,937
  • 2
  • 25
  • 32
Rob Hope
  • 33
  • 4
  • 3
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Pictures of code aren't helpful; we don't want to have to retype that. – MrFlick Dec 05 '18 at 16:37

2 Answers2

2

You need to start with some plot. polygon just adds to an existing plot. Also, You need to include a few extra points to get the area under the curve, not over.

x2 = c(x, 40, 25)
y2 = c(y, 0, 0)
plot(x,y, type="n")
polygon(x2,y2, col="yellow")

Polygon

G5W
  • 36,531
  • 10
  • 47
  • 80
2

Here is another way.

x <- 25:40
y <- dpois(x, 23.83)
plot(x, y, type = "n")
polygon(c(x, rev(x)), c(y, rep(0, length(y))), col = "yellow")

enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66