Suppose I have this example data.frame:
df <- data.frame(y=c(rnorm(150, 2, 1), rnorm(100, 1, 1.5), rnorm(200, 3, 0.75)), x=c(rep("c1", 150),rep("c2", 100),rep("c3", 200)), color=c(rep("gray",150),rep("red",150),rep("blue",150)))
and I would like to use the panel.violin function of bwplot, such that the violins are filled with the colors that correspond to the y's in df.
Obviously the following doesn't work:
bwplot(y ~ x, data = df, horizontal=FALSE, xlab=unique(df$x),
panel = function(..., box.ratio) {
panel.violin(..., col = df$color, varwidth = FALSE, box.ratio = box.ratio)
panel.bwplot(..., col='black', cex=0.8, pch='|', fill="white", box.ratio = .1)},
par.settings = list(box.rectangle=list(col='black'),
plot.symbol = list(pch='.', cex = 0.1)),
scales=list(x=list(rot=45, cex=0.5)))
One more thing that would be nice is to be able to disable the default x axis of panel.violin
It's been a while, but it turned out that a search on the rhelp archives pulled up an effort of mine 4 years ago in that venue: My argument for needing to construct a substitute panel function was ... "it required a minor hack to panel.violin, since in its native state
panel.violinonly passes a single-element vector the the grid plotting functions."Do need to load grid as well: