Hello,

I am trying to give different colors to boxes in a violin plot obtained via bwplot from lattice package using a color palette from RColorBrewer:

> require(RColorBrewer)
> MyPalette <- brewer.pal(6, "Set3")

A call to:

> boxplot(count ~ spray, data = InsectSprays, col = MyPalette)

yields the example boxplot with each box colored according to the different colors from MyPalette. In addition, boxes are colored with the same color order of MyPalette. See

> display.brewer.pal(6, "Set3")

However, when I do the same thing with a violin plot from the lattice package
> require(lattice)
> bwplot(count ~ spray, data = InsectSprays,
+        panel = function(..., box.ratio) {
+            panel.violin(..., col = "transparent",
+                         varwidth = FALSE, box.ratio = box.ratio)
+            panel.bwplot(..., fill = MyPalette, box.ratio = .1)
+        } )

boxplots are colored with the right colors (each box has a different color) but with a different color order -- too bad because I would like to color code the plot according to certain pre-defined colors. Same thing (wrong color order) with a simple bwplot:

> bwplot(count ~ spray, data = InsectSprays, fill = MyPalette)

Is there a way to get the right color (i.e. same order as in MyPalette) in bwplot/panel.violin?

Kind regards,

Luigi

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to