Skip to content Skip to navigation
University of Warwick
  • Study
  • |
  • Research
  • |
  • Business
  • |
  • Alumni
  • |
  • News
  • |
  • About
  • Text only
  • |
  • Sign in
  • Search MOAC
  • Search University of Warwick
  • Search for people at Warwick
  • Search Warwick Blogs
  • Search past exam papers
  • Search video
  • More…

    Molecular Organisation and Assembly in Cells

    • Why MOAC?
    • MOAC Research
    • MOAC People
    • MOAC Degrees
    • Study at MOAC
    • MOAC News
    • MOAC Students »
    • Peter Cock »
    • R Programming »
    • 3D Bar Charts
    University of Warwick

    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:

    [3D outut from R and RGL] [3D outut from R and RGL]

    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:

    [3D outut from R and RGL] [3D outut from R and RGL]

    Finally, the demo uses a set of cuboids to display a 3D-histogram:

    [3D outut from R and RGL] [3D outut from R and RGL]

    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]
    The R Project

     

    [RGL unofficial logo]
    RGL : R and OpenGL

     

    [OpenGL Logo]
    OpenGL

    MOAC DTC, Coventry House, University of Warwick, Gibbet Hill Road, Coventry, CV4 7AL
    Tel. 024 765 75808 moac2 at warwick dot ac dot uk

    How to find us

    MOAC Intranet

    EPSRC logo

    Close this email form
    Page contact: Peter Cock Last revised: Thu 14 Dec 2006
    • Sign in
    • |
    • Powered by Sitebuilder
    • |
    • © MMXIII
    • |
    • Terms
    • |
    • Privacy
    • |
    • Cookies
    • |
    • Accessibility