On 02.11.2010 20:08 (UTC+1), David Winsemius wrote:

On Nov 2, 2010, at 2:32 PM, Rainer Hurling wrote:

On 02.11.2010 19:08 (UTC+1), David Winsemius wrote:
On Nov 2, 2010, at 1:19 PM, Rainer Hurling wrote:

Inspired by colouring the dots of box-whisker plots I am trying to
also fill the boxes (rectangles) with different colours. This seems
not to work as I expected.

Looking at the help page of panel.bwplot it says: 'fill - color to
fill the boxplot'. Obviously it is only intended to fill all boxes
with only one colour?

Nevertheless the following example shows, that 'fill' from
panel.bwplot is able to work with more than one colour. But this only
works with one colour or multiples of 5 colours:


-------------------------------------------------
bp1 <- bwplot(voice.part ~ height, data = singer, main="1 color works",
panel = function(...) {
panel.bwplot(col=c("yellow"),
fill=c("yellow"), ...)
})

bp2 <- bwplot(voice.part ~ height, data = singer, main = "3 colors do
NOT work",
panel = function(...) {
panel.bwplot(col=c("yellow","blue","green"),
fill=c("yellow","blue","green"), ...)
})

bp3 <- bwplot(voice.part ~ height, data = singer, main = "5 colors do
work",
panel = function(...) {
panel.bwplot(col=c("yellow","blue","green","pink","red"),
fill=c("yellow","blue","green","pink","red"), ...)
})

plot(bp1, split=c(1,1,1,3))
plot(bp2, split=c(1,2,1,3), newpage=FALSE)
plot(bp3, split=c(1,3,1,3), newpage=FALSE)
-------------------------------------------------

Is there any chance to use more than one filling colour correctly?


Thanks for answering.

You have eight boxes to fill and 8 dots to color. You can either supply
8 distinct colors or you can supply some lesser number and they will be
recycled across the entire 8 boxes and dots. What you cannot do ( and
expect to see the dots against the fill background) is plot the dots as
the same colors as the fill.

It was not my intention to get the dots coloured in the same colour as
the boxes. Instead I am looking for a method to fill the boxes with a
predefined set of different colours (from a color vector). As far as I
can see this is only possible for one colour and multitudes of five
colours.

I think first I have to apologise for my bad english. Sorry for any misunderstandig.

Huh? My example used 4 colors. It should have worked with eight colors
as well. There are eight groups and

Yes, all is ok with your example. My only problem is, the these four colours are not ordered as given by the vector (see below).

The dots should remain uncoloured ...

Then leave out the col= argument (assuming uncolored means black.)

I used these coloured dots to explain, that ordered colours (from given vector) work with dots, but not with the boxes.

This will let you see all colors of dots and fill with only 4 colors
because I set it up so there was no two identical colors in teh sequence
of dots and fill during hte reculing:

bp4 <- bwplot(voice.part ~ height, data = singer, main = "5 colors do
work",
panel = function(...) {
panel.bwplot(col=rev(c("yellow","blue","green","pink")),
fill=c("yellow","blue","green","pink"), ...)
})

In your example you can see that the dots colors are painted in the
right (reversed) order, the boxes are painted as sequence
c("yellow","pink","green","blue") instead of
c("yellow","blue","green","pink").

I do not understand how to turn over a given order and with a given
count of colours to the boxes.

See if this example using selected colors() works to make it clearer:

 > colors()[(2:9)*10]
[1] "bisque1" "blue4" "burlywood3" "chartreuse3" "coral3"
[6] "cyan2" "darkgray" "darkorange"


bp5 <- bwplot(voice.part ~ height, data = singer, main = "5 colors do
work",
panel = function(...) {
panel.grid(v = -1, h = 0)
panel.bwplot(fill=colors()[(2:9)*10], ...)
})

bp5

(Needed to avoid the first colors() because they were mostly variants of
"white".
 > colors()[1:8]
[1] "white" "aliceblue" "antiquewhite" "antiquewhite1"
[5] "antiquewhite2" "antiquewhite3" "antiquewhite4" "aquamarine"

Of course your example with eight colours works, too. But as you can see in the plot, the colours have different order then in the vector 'colors()[(2:9)*10]' itself. I expected the first box (bass2) coloured "bisque1", the second box (bass1) "blue4" and so on.

I hope, this explaination is a bit clearer than my preceding ones.

Thanks in advance,
Rainer Hurling

______________________________________________
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