简体   繁体   English

绘制以在R中的线形图上添加多边形

[英]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. 我已经使用R中的overlapPlot()函数用数据制作了以下图表。

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. 日出在6-7之间,日落在18-19之间。

To do this I thought I could use the polygon() function. 为此,我认为我可以使用polygon()函数。 However I am not sure how to code the polygon function to do this. 但是我不确定如何编码多边形函数来做到这一点。 Any help would be appreciated. 任何帮助,将不胜感激。

在此处输入图片说明

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM