简体   繁体   English

ggplot2 3D 酒吧 Plot

[英]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:我只是想使用'ggplot2'package在'R'中尝试plot a 3D bar plot。我的dataframe看起来像这样:

 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:我想要 plot 这样的东西:在此处输入图像描述

Any help is more than appreciated!!非常感谢任何帮助!

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. 如评论中所述,3D绘图通常不是一个好选择(如果有其他选项可用),因为3D绘图往往会给数据提供失真/模糊的视图。

That said, here's how you can plot your data as desired with latticeExtra : 就是说,这是您可以根据需要使用latticeExtra绘制数据的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")))

在此处输入图片说明

The {rayshader} package is another package that allows 3D visualisation - according to the author, it will only allow 3d visualisation for data that has indeed three dimension. {rayshader} package 是另一个 package,它允许 3D 可视化 - 根据作者的说法,它只允许 3d 可视化确实具有三个维度的数据。 Here based on a tile plot .这里基于磁贴 plot

NB: the below required for me to install current GitHub versions of both the rayshader (v.0.33.3) and rgl (v.1.0.0) packages.注意:以下要求我安装 rayshader (v.0.33.3) 和 rgl (v.1.0.0) 包的当前 GitHub 版本。

# devtools::install_github("tylermorganwall/rayshader") ## NB this will install a lot of dependencies
library(rayshader)
library(ggplot2)
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)

p <- ggplot(d, aes(x, z, fill = y)) +
  geom_tile() +
  scale_fill_fermenter(type = "div", palette = "RdYlBu")

plot_gg(p)
render_movie(filename = "plot.gif")

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM