0

I'm using coding provided here to plot a mahattan plot, but it does the abline behind my actual data points when I need to have it superposed to it. https://genome.sph.umich.edu/wiki/Code_Sample:_Generating_Manhattan_Plots_in_R

I have tweaked around but unable to figure it out.

    xyplot(logp~genpos, chr=chr, groups=grp,
        axis=axis.chr, ann.settings=ann.settings, 
        prepanel=prepanel.chr, scales=list(axs="i"),
        panel=function(x, y, ..., getgenpos) {
            if(!is.na(sig.level)) {
                #add significance line (if requested)
                panel.abline(h=-log10(sig.level), lty=2);
            }
            panel.superpose(x, y, ..., getgenpos=getgenpos);
            if(!is.null(panel.extra)) {
                panel.extra(x,y, getgenpos, ...)
            }
        },
        panel.groups = function(x,y,..., subscripts, group.number) {
            A<-list(...)
            #allow for different annotation settings
            gs <- ann.settings[[group.number]]
            A$col.symbol <- gs$col[(as.numeric(chr[subscripts])-1) %% length(gs$col) + 1]    
            A$cex <- gs$cex[(as.numeric(chr[subscripts])-1) %% length(gs$cex) + 1]
            A$pch <- gs$pch[(as.numeric(chr[subscripts])-1) %% length(gs$pch) + 1]
            A$fill <- gs$fill[(as.numeric(chr[subscripts])-1) %% length(gs$fill) + 1]
            A$x <- x
            A$y <- y
            do.call("panel.xyplot", A)
            #draw labels (if requested)
            if(gs$label$show) {
                gt<-gs$label
                names(gt)[which(names(gt)=="text")]<-"labels"
                gt$show<-NULL
                if(is.character(gt$x) | is.character(gt$y)) {
                    peak = which.max(y)
                    center = mean(range(x))
                    if (is.character(gt$x)) {
                        if(gt$x=="peak") {gt$x<-x[peak]}
                        if(gt$x=="center") {gt$x<-center}
                    }
                    if (is.character(gt$y)) {
                        if(gt$y=="peak") {gt$y<-y[peak]}
                    }
                }
                if(is.list(gt$x)) {
                    gt$x<-A$getgenpos(gt$x[[1]],gt$x[[2]])
                }
                do.call("panel.text", gt)
            }
        },
        xlab=xlab, ylab=ylab, 
        panel.extra=panel.extra, getgenpos=getGenPos, ...
    );
}
thelatemail
  • 91,185
  • 12
  • 128
  • 188
  • 1
    You might want to consider some of the info here - https://stackoverflow.com/questions/56747471/how-can-i-ask-a-great-ggplot-lattice-base-plot-question - if you can reduce the question down to a very simple piece of code with only the relevant, representative code to the exact issue you are facing it will be much more approachable. There's a lot of irrelevant code here that any potential answerer will have to dig through, and many will just not be bothered. – thelatemail Jun 25 '19 at 23:21
  • I edited to the piece that's most relevant. Thanks – Madza Farias-Virgens Jun 25 '19 at 23:24
  • 1
    The functions are drawn in the order they are encountered in the `panel=` function argument. If you want the `abline` on top, move that line to the end of the panel function. – MrFlick Jun 26 '19 at 00:03
  • Yup It worked. Thxs! – Madza Farias-Virgens Jun 26 '19 at 01:02

0 Answers0