R histogram - too many variables

…衆ロ難τιáo~ 提交于 2019-12-08 14:05:13

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/6428432/r-histogram-too-many-variables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!