Guest
Guest

Reputation: 17

Draw to add a polygon on my line graph in R

I have made the folowing graph with my data using the overlapPlot() function in R.

I would like to add to shaded areas within the graph showing sunrise and sunset. Sunrise is between 6-7 and sunset between 18-19.

To do this I thought I could use the polygon() function. However I am not sure how to code the polygon function to do this. Any help would be appreciated.

enter image description here

Upvotes: 0

Views: 1229

Answers (1)

Guest
Guest

Reputation: 17

I used the following code:

#SUNRISE
    cord.x <- c(5.52)
    cord.y <- c(0)

    cord.x <- c(cord.x,5.52) 
    cord.y <- c(cord.y,4)

    cord.x <- c(cord.x,8.37,8.37)
    cord.y <- c(cord.y,4,0)
    polygon(cord.x,cord.y,col=adjustcolor("blue",alpha.f=0.4),border=NA)

#SUNSET
    cord.x <- c(-5.56)
    cord.y <- c(0)

    cord.x <- c(cord.x,-5.56) 
    cord.y <- c(cord.y,4)

    cord.x <- c(cord.x,-8.48,-8.48)
    cord.y <- c(cord.y,4,0)
    polygon(cord.x,cord.y,col=adjustcolor("blue",alpha.f=0.3),border=NA)

Upvotes: 1

Related Questions