Change background color of R plot

后端 未结 6 1174
北恋
北恋 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条回答
  •  有刺的猬
    2020-12-13 18:05

    I use abline() with extremely wide vertical lines to fill the plot space:

    abline(v = xpoints, col = "grey90", lwd = 80)

    You have to create the frame, then the ablines, and then plot the points so they are visible on top. You can even use a second abline() statement to put thin white or black lines over the grey, if desired.

    Example:

    xpoints = 1:20
    y = rnorm(20)
    plot(NULL,ylim=c(-3,3),xlim=xpoints)
    abline(v=xpoints,col="gray90",lwd=80)
    abline(v=xpoints,col="white")
    abline(h = 0, lty = 2) 
    points(xpoints, y, pch = 16, cex = 1.2, col = "red")
    

提交回复
热议问题