0

I have some data in a matrix that I would like to display as a 3D bar chart (with the "floor dimensions" representing rows and columns of the matrix, and bar height representing values. All values are positive so let's say my matrix is something like:

A <- matrix(rnorm(100)^2, ncol=10, nrow=10)

How could I accomplish that? I know a heatmap could be a valid alternative but unfortunatelly it's not up to me to choose the plot format.

As posted in the comments by Stéphane Laurent (merci beaucoup!), the result I am looking for would look close to this (maybe with a different perspective, but that's it):

enter image description here

David
  • 371
  • 2
  • 13
  • 1
    You mean something [like this](https://visjs.org/images/graph3d.png) ? – Stéphane Laurent Sep 03 '19 at 10:21
  • Yes! That's more or less what it should look like – David Sep 03 '19 at 10:24
  • So you can try my package [graph3d](https://github.com/stla/graph3d) (if you don't mind to use a non-CRAN package). I made it very quickly and it's not very elaborate. And I don't remember how it works right now, so I cannot give you the code. Look at the example in `?graph3d`. – Stéphane Laurent Sep 03 '19 at 10:31
  • @StéphaneLaurent Definitely having a look at it! – David Sep 03 '19 at 10:34

1 Answers1

1

You can try the hist3D function from the plot3D package:

library(plot3D)
set.seed(42)
A <- matrix(rnorm(100)^2, ncol=10, nrow=10)
hist3D(x= 1:nrow(A), y = 1:ncol(A), z = A)

enter image description here

There are many parameters that can be set to adapt the output to the preferred style, see ?hist3D. For instance, using border = 1 will draw a fine black line at the edges of the surfaces.

Community
  • 1
  • 1
RHertel
  • 23,412
  • 5
  • 38
  • 64
  • Yes, or plot3Drgl, see [here](https://stackoverflow.com/questions/56689216/r-shiny-htmlwidget-for-interactive-3d-histograms/56692012#56692012) for an example. The advantage of my package `graph3d` is that it produces an interactive htmlwidget, with tooltips on the bars (this package wraps the vis graph3d JS library, and it would deserve to be more developed). – Stéphane Laurent Sep 03 '19 at 10:54
  • @StéphaneLaurent That's definitely an advantage sometimes, but if you want to include your results on a report, not that much! – David Sep 04 '19 at 13:40