Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ggplot2 3D Bar Plot

I Know this sounds basic, but have a been searching for literally more than an hour now without success. I'm simply trying to plot a 3D bar plot in 'R' using the 'ggplot2' package. My dataframe looks something like this:

 x   y     z
t1   5   high
t1   2   low
t1   4   med
t2   8   high
t2   1   low
t2   3   med
t3  50   high
t3  12   med
t3  35   low

and I want to plot something like this on it: enter image description here

Any help is more than appreciated!!

like image 416
Tavi Avatar asked Nov 07 '14 04:11

Tavi


People also ask

Can Ggplot create 3D chart?

Unfortunately, at the time of writing (April 2021), ggplot2 does not natively support 3d plots.

How do I make Ggplot 3D?

To transform an existing ggplot2 object into 3D, you simply drop the object into the plot_gg() function–rayshader handles the dirty work of stripping out all non-data elements, remapping the data, ray tracing shadows, and plotting it in 3D1Utilizing the rgl package.

What is 3D bar chart?

A bar 3D chart represents quantitative information. The chart consists of horizontally aligned rectangular bars of equal width with lengths proportional to the values they represent, something that aids in instant comparison of data. One axis of the chart plots categories and the other axis represents the value scale.


1 Answers

As mentioned in comments, 3D plots usually aren't a good choice (when other options are available) since they tend to give a distorted/obscured view of data.

That said, here's how you can plot your data as desired with latticeExtra:

d <- read.table(text=' x   y     z
t1   5   high
t1   2   low
t1   4   med
t2   8   high
t2   1   low
t2   3   med
t3  50   high
t3  12   med
t3  35   low', header=TRUE)

library(latticeExtra)

cloud(y~x+z, d, panel.3d.cloud=panel.3dbars, col.facet='grey', 
      xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col=1), 
      par.settings = list(axis.line = list(col = "transparent")))

enter image description here

like image 174
jbaums Avatar answered Sep 19 '22 17:09

jbaums