verbose=FALSE
datafile<-file.choose()
load(datafile)
proceed=FALSE
if (exists("garn")) {proceed=TRUE}
nplots=1

This report plots the frames of existence of each id'd fly over the experimental protocol. Data is extracted from the garn list from the data file r paste(dirname(datafile),basename(datafile),sep="/").

r if (proceed) {("This does *not* guarantee that identity is correctly assigned.")} else {("The plotting cannot proceed as the data file does not contain the appropriate variable.")}

multiplot <- function(plots, cols) {
  library(grid)

  numPlots = length(plots)

    # Make the panel
    # ncol: Number of columns of plots
    # nrow: Number of rows needed, calculated from # of cols
    layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
                     ncol = cols, nrow = ceiling(numPlots/cols))

  if (numPlots==1) {
    print(plots[[1]])

  } else {
    # Set up the page
    grid.newpage()
    pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))

    # Make each plot, in the correct location
    for (i in 1:numPlots) {
      # Get the i,j matrix positions of the regions that contain this subplot
      matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))

      print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
                                      layout.pos.col = matchidx$col))
    }
  }
}
require(ggplot2)
t<-garn[[1]]$trx$t

plotlist<-list()
nplots<-length(garn)

for (i in 1:nplots) {
  plotlist[[i]]<-ggplot(data=garn[[i]]$trx) +
                 geom_ribbon(data=t, aes(x=time,ymin=0,ymax=lit),colour=NA,fill='orange',alpha=0.6) +
                 geom_path(aes(x=time,y=id/max(id),colour=factor(id))) +
                 ggtitle(names(garn)[i]) +
                 theme(axis.title.y=element_blank(),
                       axis.text.y=element_blank(),
                       axis.ticks.y=element_blank(),
                       panel.background=element_blank(),
                       panel.border=element_blank(),
                       panel.grid.major=element_blank(),
                       panel.grid.minor=element_blank(),
                       plot.background=element_blank(),
                       legend.position="none")
}
multiplot(plots=plotlist,cols=3)


PaolaCognigni/CTraxHelper documentation built on May 7, 2019, 11:57 p.m.