Search code examples
rgraphlattice

Break axis in R


Recently I had some problems representing some data with xyplot. Everything appears very nicely but my boss asked me to break the axis (I'm not very fan of break axis). So far I have been able to do this with the function shingle, yet the order of panels is such a mess that read the information is imposible. In addition, I would like strips showing only the variable cs no the st (information specified in my sample data.frame) on the graphic. Then, the real challenge is to fix all this requirements into lattice, which is the internal standard for graphics in the group.

Here is my example data.frame (http://1drv.ms/1JOKSPU) sample of code:

AA<-read.csv("~/example.csv",header = T,sep = ";",dec = ",")
    AA$st <-
      shingle(Indl.Data$t,
              intervals = rbind(c(0, 14),
                                c(23, 26)))
    AA<-AA[with(AA, order(t)), ]



    my.panel.1 <- function(x, y, subscripts, col, pch,cex,sd,...) {
      low95 <- y-sd[subscripts]
      up95 <- y+sd[subscripts]
      panel.xyplot(x, y, col=col, pch=pch,cex=cex, ...)
      panel.arrows(x, low95, x, up95, angle=90, code=3,lwd=3, 
                   length=0.05, alpha=0.5,col=col)
    }
    xyplot( logOD~t|cs+st,
            data=AA,
            strip = T,
           sd=0,
            groups=cs,
            xlab = list("Time ", cex=1.5), 
            ylab = list("growth", cex=1.5),
            type="p",
            col=c("red","black"),
            scales = list(x = "free"), between = list(x = 0.5),
            panel.groups="my.panel.1", 
            panel="panel.superpose",
            par.settings = list(layout.widths = list(panel = c(6, 2))))

This is what I get with this: AS can be noticed upper line has the times higher than 24h and the lower line the lower times. My target is to make a continuum with an hypothetic panel 1( cs=X t0-t15) and next to it a narrower panel 2 ( cs=X t23-t26)

In advance, sorry if there is any mistake in the formulation of my question, I do not have a programming background and this is me third question.

Cheers;


Solution

  • You want to go through st and then cs. So try xyplot( logOD~t|st+cs,.

    Maybe use layout=c(4,3) if needed. And as.table=TRUE if you want it to start in upper left.