0

So I have a dotplot with 4 panels, each panel has 6 horizontal bars. I'm trying to make it so that when a bar is past a certain X value (denoted by reference line), it will be a different color. I cant find anything that will make R do this automatically, soI figured there must be a way to manually tell it to make a specific row of a specific panel a certain color? Heres my code:

dotplot(somematrix,groups=FALSE,
        layout=c(2,2),aspect=1,
        origin=0,type=c("p","h"),
        main="Main label",
        xlab="X label",
        scales=list(x=list(tck=0, alternating=TRUE)),
        panel=function(...){
            panel.fill(rgb(.9,.9,.9))
            panel.grid(h=0,v=-1,col="white",lwd=2)

            panel.abline(v=20,col="red",lwd=3)
            panel.barchart(col=c("blue","blue","blue","blue","red","blue"),cex=1.1,...)
        }
)
Ksims
  • 17
  • 5
  • Depending what exactly you want to do, you might want to first have a look at the interactive functions documented in `?trellis.focus`, and then, once you've got code that draws what you want, make it only get called for certain values of `panel.number()`. (See [here](http://stackoverflow.com/questions/24283828/assigning-colours-to-plots-in-lattice-according-to-set-or-factor-not-groups/24287977#24287977), [here](http://stackoverflow.com/a/9752056/980833), and [here](http://stackoverflow.com/a/16577667/980833) for a few examples of `panel.number()` in action.) – Josh O'Brien Oct 30 '15 at 19:01
  • Thanks! these are very helpful examples – Ksims Nov 01 '15 at 18:01
  • Ah good. Feel free to upvote whichever ones help out, as that'll help highlight them as useful answers. – Josh O'Brien Nov 01 '15 at 18:06
  • So, I spent the weekend playing around with it. Seems like I dont understand the panel.number(). The examples you posted make sense. I can assign a color to a panel, or to a specific row, but I cant figure out how to make a certain row in a selected panel a different color. Ex: all rows in all panels "red" except for row 2 of panel 1. Any more hints would be greatly appreciated! – Ksims Nov 02 '15 at 03:30

0 Answers0