I know this issue has been discussed before, but I hoped the advent of 
pretty.Date would resolve it. In the following code, the first plot produces 
misaligned vertical grid lines, while in the second plot they are properly 
aligned. Is there any way to get something along the lines of the first call to 
produce properly aligned grid lines?

X <- data.frame(date=seq(as.Date("1990/01/01"), as.Date("2010/11/24"), by=1))   
                                                                                
                   
X$value <- rnorm(length(X$date))                                                
                                                                                
                   
                                                                                
                                                                                
                   
## This produces grid lines not aligned with the date ticks                     
                                                                                
                   
                                                                                
                                                                                
                   
xyplot(value ~ date, data=X,                                                    
                                                                                
                   
       panel = function(...) {                                                  
                                                                                
                   
         panel.grid(v=-1,h=-1,col="black")                                      
                                                                                
                   
         panel.xyplot(...)                                                      
                                                                                
                   
       })                                                                       
                                                                                
                   
                                                                                
                                                                                
                   
## This produces grid lines aligned with the date ticks                         
                                                                                
                   
                                                                                
                                                                                
                   
xyplot(value ~ date, data=X,                                                    
                                                                                
                   
       panel = function(...) {                                                  
                                                                                
                   
         panel.abline(v=pretty(X$date, 5))                                      
                                                                                
                   
         panel.grid(v=0,h=-1,col="black")                                       
                                                                                
                   
         panel.xyplot(...)                                                      
                                                                                
                   
       })                                        

Thanks.

- Elliot

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to