3D Bar Charts using RGL
I recently wanted to draw some 3D Bar Charts or 3D histograms in R - Cuboids layed out on a rectangular grid. This is very easy in most spreadsheet packages, but doesn't seem to be built into R.
Not to fear, if you install the RGL package (an interface from R to the OpenGL graphics libraries) we can do this and much more. Plus, we can move the figures in real-time by dragging them with the mouse!
library(rgl)
demo(hist3d)
This will produce three interactive plots in their own windows, and show you the R code to do this. In each case I have shown two views - before and after I changed the viewpoint with the mouse. First of all, there is a simple cuboid with a red top plane:
![Cuboid drawn with RGL [3D outut from R and RGL]](rgl_hist3d_demo1a.png?maxWidth=264&maxHeight=290)
Then they show you an "exploded cuboid" to show you that its simply made up of six rectangles. The demo code also changes the background colour too:
![Exploded cuboid drawn with RGL [3D outut from R and RGL]](rgl_hist3d_demo2a.png?maxWidth=264&maxHeight=290)
Finally, the demo uses a set of cuboids to display a 3D-histogram:
![3D histogram drawn with RGL [3D outut from R and RGL]](rgl_hist3d_demo3a.png?maxWidth=264&maxHeight=290)
Very nice... especially when you spin it round and round, but I think it needs a bit of work to use for real data - adding labelled axes for a start.
![[R logo]](/fac/sci/moac/people/students/peter_cock/r/rlogo2.png?maxWidth=125&maxHeight=76)
![[RGL unofficial logo]](/fac/sci/moac/people/students/peter_cock/r/rgl.png?maxWidth=134&maxHeight=100)
![[OpenGL Logo]](../opengl_animated.gif)