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:
Any help is more than appreciated!!
Unfortunately, at the time of writing (April 2021), ggplot2 does not natively support 3d plots.
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.
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.
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")))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With