Grid line consistent with ticks on axis

后端 未结 4 1047
悲&欢浪女
悲&欢浪女 2020-12-13 14:38

I am embarrassed to ask this simple question, but has been in kicking my mind for several days whenever I create a plot:

plot (x = 1:10, y = rnorm (10, 5, 2)         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-13 15:16

    For reference, there is a way to control the grid and axes parameters directly from the plot() command, if we are not defining a custom tick interval:

    plot(x = 1:10, y = rnorm(10, 5, 2), xlim=c(1, 10), ylim=c(1, 10), panel.first=grid())
    

    The plot.default() documentation gives more information about these parameters.

    When using a custom ticks interval, the easiest is to draw the grid using abline:

    plot(x = 1:10, y = rnorm(10, 5, 2), xaxp=c(1, 10, 10), yaxp=c(1, 10, 10), axes=FALSE)
    axis(1, 1:10)
    axis(2, 1:10)
    abline(h=1:10, v=1:10, col="gray", lty=3)
    

    grid example

    More information about custom tick intervals in this thread and here for grid alignment.

提交回复
热议问题