Plotting a grid behind data, not in front in R

前端 未结 5 887
一生所求
一生所求 2020-12-30 23:45

I like to produce my own grid lines when plotting so I can control tick marks, etc. and I am struggling with this with the \'hist\' plotting routine.

    his         


        
5条回答
  •  一个人的身影
    2020-12-31 00:30

    The base graphics solution suggested by @joran is fine. Alternatives:

    d <- data.frame(x=rnorm(1000))    
    
    library(lattice)
    histogram(~x,data=d,panel=function(...) {
         panel.grid(...)
         panel.histogram(...) } 
    )
    

    Or:

    library(ggplot2)
    qplot(x,data=d,geom="histogram",binwidth=0.1)+theme_bw()+
       labs(x="Wind speed", y="Frequency")
    

    (But of course you will have to learn all the details of adjusting labels, titles, etc. ... I'm not actually sure how to do titles in ggplot ...)

提交回复
热议问题