我想要如下编码的堆栈图表,但我希望它们看起来是立方体的(附后)。在 R 中是否可能?
set.seed(123)
specie <- c(rep("sorgho" , 3) , rep("poacee" , 3) , rep("banana" , 3) , rep("triticum" , 3))
condition <- rep(c("normal" , "stress" , "Nitrogen", "T") , 3)
value <- abs(rnorm(12, 0 ,15))
data <- data.frame(specie,condition,value)
# Stacked
ggplot(data, aes(fill=condition, y=value, x=specie)) +
geom_bar(position="stack", stat="identity", alpha = 0.7, width = 0.3) + theme_classic()
最佳答案
这可以通过未发布的 ggrgl 实现。包等。将其应用到您的示例中,我们有:
remotes::install_github('coolbutuseless/devout')
remotes::install_github('coolbutuseless/devoutrgl')
remotes::install_github('coolbutuseless/ggrgl', ref='main')
library(rgl)
library(devout)
library(devoutrgl)
library(ggrgl)
library(ggplot2)
p <- ggplot(data, aes(fill=condition, y=value, x=specie, z =2,
extrude_face_fill = condition)) +
geom_bar_z(position="stack", stat="identity", width = 0.3, extrude = TRUE,
color = "black") +
theme_classic()
devoutrgl::rgldev()
p
invisible(dev.off())
结果是一个可旋转的 3D ggplot:
关于r - 如何在 R ggplot2 中创建看起来立方体(3D)的堆栈条形图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72720874/