[R] show 0 at y axis in xyplot lattice

Maria Lathouri mlathouri at yahoo.gr
Mon Sep 11 21:33:25 CEST 2017


Dear all
I am trying to make a plot in xyplot lattice by groups. I would like to show "0" in y axis but I don't want to be aligned with the x axis. I want to be a little bit above.
I have tried many options but I don't get what I want. I also tried ylim=c(0, 80) but both 0 and 80 are fully aligned with the x-axis and the upper boundary of the plot, respectively:
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), ylim=c(0, 80),
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)), 
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"), 
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")               
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")              
         panel.xyplot(x, y, ...)
         }
         )
when I use the following, 80 is a bit lower than the upper boundary of the plot, which is what I want, but 0 is not showing: 
xyplot(upper.zn + Zn2 + lower.zn ~ sdate | Location, type="b", as.table=TRUE, data=dat, pch=c(22, 21, 22), lty=c(2, 1, 2), 
       index.cond=list(c(3, 1, 2)), ylab="Percent (%)", par.strip.text=list(col="white", font=2, lines=1.5),
       lattice.options = modifyList(lattice.options(), list(skip.boundary.labels = 0)), 
       par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", "black", "red"), 
       key=dat_key, scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y")), y=list(at=c(0, 20, 40, 60, 80))), xlab="Date",
       panel = function(x, y, ...) {
         panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")               
         panel.abline(v=sdate, lwd=1, lty=3, col="grey")              
         panel.xyplot(x, y, ...)
         }
         )I have also attached a reproducible example in case you want to see in more detail my data. 
I would very much appreciate any suggestions on this. 
Thank you in advance.
Kind regards,Maria
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: savedat.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20170911/9910a9f7/attachment.txt>


More information about the R-help mailing list