Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

How to draw a colorbar in rgl?

$
0
0

I have plotted a mesh in rgl to visualize data on it. I.e., the mesh has colors that originate from applying a colormap to its data (one scalar value at each vertex). Here is a minimal example that consists of a mesh with a single face:

library(rgl);
library(squash);

# create a mesh
vertices <- c( 
    -1.0, -1.0, 0, 1.0,
    1.0, -1.0, 0, 1.0,
    1.0,  1.0, 0, 1.0,
    -1.0,  1.0, 0, 1.0
)
indices <- c( 1, 2, 3, 4 )

# add a data value for each vertex
morph_data = rnorm(length(indices), mean = 3, sd = 1)

# create colors from values by applying a colormap
col = squash::cmap(morph_data, map = squash::makecmap(morph_data, colFn = squash::jet));

# plot
open3d()  
shade3d( qmesh3d(vertices, indices), col=col )

How can I add a colorbar to this plot in rgl?

An example for what exactly I mean with colorbar is shown in the right part of this example picture from octave.sourceforge.io.


Viewing all articles
Browse latest Browse all 201867

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>