Change background color of R plot

后端 未结 6 1306
北恋
北恋 2020-12-13 17:25

All right, let\'s say I have the following plot.

df = data.frame(date=c(rep(2008:2013, by=1)),
                value=c(303,407,538,696,881,1094))

barplot(df         


        
6条回答
  •  旧时难觅i
    2020-12-13 18:08

    After combining the information in this thread with the R-help ?rect, I came up with this nice graph for circadian rhythm data (24h plot). The script for the background rectangles is this:

    root script:

    >rect(xleft, ybottom, xright, ytop, col = NA, border = NULL)
    

    My script:

    >i <- 24*(0:8)
    >rect(8+i, 1, 24+i, 130, col = "lightgrey", border=NA)
    >rect(8+i, -10, 24+i, 0.1, col = "black", border=NA)
    

    The idea is to represent days of 24 hours with 8 h light and 16 h dark.

    Cheers,

    Romário

提交回复
热议问题