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.