-1

I am trying to illustrate a histogram of 33 different variables. Due to the number of variables I think "beside" different Colors I need to label each bar in a clear way, even using an arrow, if its doable.

I was wondering about 1) How can I define 33 distinct color in R 2) How can I label them, say vertical below X axis with a certain distance from each other to make my figure more clear.

I am using multhist function from Plotrix package, and for data you can image just 33 random vector with different length !

Thanks

Areza
  • 5,623
  • 7
  • 48
  • 79
  • also, this should be asked on [http://stats.stackexchange.com/](http://stats.stackexchange.com/) – Jacob Eggers Jun 21 '11 at 16:09
  • 1
    And post some sample data and reproducible code. – Andrie Jun 21 '11 at 16:28
  • 1
    @Jacob, looks like a perfectly good programming question to me. Also, this comment made me giggle (from R chatroom): *I recommend introducing infrared and ultraviolet colors into the pallet for improved bandwidth. -- JD Long* – Roman Luštrik Jun 21 '11 at 16:29
  • @Gavin, Honestly I haven't got any complete answer so flag it as a final solution. If you look at other questions, all answers were along with my comments to remind the problem to other users who made comments, in other side I don't have enough reputation to put up some question. – Areza Jun 22 '11 at 21:29
  • @Jacob, my question doesn't have any content of statistical issue ! its just matter of illustration and some R techniques – Areza Jun 22 '11 at 21:30

2 Answers2

6

As Chris mentioned, trying to distinguish 33 colours doesn't work for humans. You need to find a different plot type that doesn't rely on only colour.

Without a reproducible example, it is not possible to say what this plot should be, but here's some generic colour advice.

Use HCL colours rather the RGB or HSV. Read Escaping RGBland by Achim Zeileis for an explanation. There are some useful functions for generating palettes in the colorspace package.

If your variables are unordered categories (i.e., encoded as factors) then your colours should have different hues. (Use rainbow_hcl.)

If your variables are in some sort of order (ranges or ordered factors) then your colours should have different lightness or chroma. (Use sequential_hcl.) A variation on this is if they differ about some midpoint, in which case you need diverge_hcl.

Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • My variables are so integrated and using colors alone would be a bit messy, so I meant how can some labels vertically on X axis, to indicate that each bar is belong to which variable. Or is there any way to use an arrow to point at a certain bar ? and as final word, if you were me, what would have you done ?! – Areza Jun 22 '11 at 21:33
2

You can define colors in R in any number of ways; try ?rainbow or ?greyscale for some suggestions

You could also look at all the colors here and just create a vector of your desired colors that you call inside your plot function.

Your problem though is that the human eye and the printing process has trouble distinguishing and reproducing that many distinct colors. See the documentation at the colorbrewer site for more information (and advice on picking colors).

Not sure I understand what your trying to do with the labels, but you can re-label an axis with a call to axis. See the documentation in ?axis.

joran
  • 169,992
  • 32
  • 429
  • 468
Chris
  • 418
  • 3
  • 10
  • I had this idea to write labels on x axis vertically, or showing some with arrows if its possible – Areza Jun 21 '11 at 22:14
  • You can do that with axis. Please do try reading the documentation. As for arrows, you'll have to do that seperately try ?arrows – Chris Jun 21 '11 at 22:25