0

As it is suggested in this , we can add a legend to an rgl 3d plot as in the following.

legend3d("topright", legend = paste('Type', c('A', 'B', 'C')), pch = 16, col = rainbow(3), cex=1, inset=c(0.02))

But this works only if we have few plotting colors and classes. For example, For 7 classes, we simply provide 7 colors (e.g. rainbow(7)) and 7 labels. But there are times when we don't even know the number of classes/colors we have in our plot. Is there anyway out where our plotting function uses a color palette that we can use latter to draw a legend or color scale bar? Here attached is my 3d plot image and I want to add a legend for every class I have.enter image description here

Community
  • 1
  • 1
Desta Haileselassie Hagos
  • 23,140
  • 7
  • 48
  • 53
  • Do you have a minimal example to produce the plot? It seems to me like your solution would simply to supply the number of factor levels you have into your palette function in the legend. If your problem is how to find that palette, then that minimal example would help. – sebastian-c Jan 19 '16 at 13:48
  • @sebastian-c, well, I am using this evaluation dataset in case you want to reproduce the plot: http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html – Desta Haileselassie Hagos Jan 19 '16 at 15:38
  • It might be a little easier if you use `head` on that data (or just grab a row for each colour) and then show the code you're using to plot. At a guess, though, I'd say that you could try something like `levels(data$colour_column)` to solve the issue. – sebastian-c Jan 25 '16 at 08:42

0 Answers0