Different interval colors in segplot in R

I need to create a segment with three segment colors: one for intervals less than 1, one for intervals greater than 1, another for intervals containing 1.

df <- read.table(header=T, text='
             geno       n   rd  lower upper
             A7002      7 1.12   0.94  1.30
             ANTA82RR  12 1.00   0.91  1.09
             BR05-83097 5 0.84   0.41  1.27
             BR05-86275 5 0.64   0.25  0.93
             BRM04-1660 7 1.26   1.02  1.50
             BRN03-1404 5 1.03   0.88  1.18
             BRN05-0656 5 0.57   0.47  0.67
             ')

library(latticeExtra)

segplot(reorder(factor(geno), rd)  ~ lower + upper,
    data = df, 
    xlim=c(-1, 2.5),
    draw.bands = FALSE, centers = rd,
    panel = function (x,y,z,...){
    panel.segplot(x,y,z,...)
    panel.abline(v=1,lty=3)
    }
 ) 

      

Thanks in advance.

+3


source to share


1 answer


For some reason segplot

, it doesn't seem to respect the parameter groups=

as most trellis plots do. Here's a kind of messy work with the first step generating your grouping variable

df$group<-with(df, ifelse(lower>1, "superior", ifelse(upper<1, "inferior","contain")))

segplot(reorder(factor(geno), rd)  ~ lower + upper,
    data = df, 
    groups=group,
    xlim=c(-1, 2.5),
    draw.bands = FALSE, centers = rd,
    panel = function(...) {
        panel.abline(v=1,lty=3)
        panel.superpose(...)
    },
    panel.groups = function (x,y,z,subscripts,col,col.line,centers,...){
        panel.segplot(x,y,z[subscripts],centers=centers[subscripts],subscripts=T,
            col=col.line,...)
    }
 ) 

      



enter image description here

+5


source







All Articles