带有误差条的3D条形图

时间:2017-10-25 04:05:49

标签: r plot 3d

我非常欣赏之前关于3D条形图的问题和答案。

ggplot2 3D Bar Plot

然而,之前的问题和答案并没有讨论如何在3D图中绘制“误差条”。

我对绘制以下类型的数据感兴趣。

v = s/v

上一个问题的答案将产生一个“无误差条”的3D条形图。

data = structure(list(x = structure(c(1L, 2L, 1L, 2L), .Label = c("FALSE", 
"TRUE"), class = "factor"), y = structure(c(1L, 1L, 2L, 2L), .Label = c("FALSE", 
"TRUE"), class = "factor"), z = c(-0.1, 0.44, 0.35, 1.14), asymp.LCL = c(-0.11, 
0.35, 0.28, 0.94), asymp.UCL = c(-0.09, 0.54, 0.42, 1.34)), .Names = c("x", 
"y", "z", "asymp.LCL", "asymp.UCL"), row.names = c(NA, 4L), class = "data.frame")



data
      x     y     z asymp.LCL asymp.UCL
1 FALSE FALSE -0.10     -0.11     -0.09
2  TRUE FALSE  0.44      0.35      0.54
3 FALSE  TRUE  0.35      0.28      0.42
4  TRUE  TRUE  1.14      0.94      1.34

image generated with library latticeExtra

如果没有使用库latticeExtra的其他解决方案,我也很感激。

请告诉我任何建议。

感谢。

1 个答案:

答案 0 :(得分:0)

我已经学会了如何在图形网格中添加图层。

data = structure(list(x = structure(c(1L, 2L, 1L, 2L), .Label = c("FALSE", 
"TRUE"), class = "factor"), y = structure(c(1L, 1L, 2L, 2L), .Label = c("FALSE", 
"TRUE"), class = "factor"), z = c(-0.1, 0.44, 0.35, 1.14), asymp.LCL = c(-0.11, 
0.35, 0.28, 0.94), asymp.UCL = c(-0.09, 0.54, 0.42, 1.34), asymp.interval = c(0.024, 
0.191, 0.144, 0.402), SE = c(0.006, 0.049, 0.037, 0.103), z_SE = c(-0.094, 
0.489, 0.387, 1.243)), .Names = c("x", "y", "z", "asymp.LCL", 
"asymp.UCL", "asymp.interval", "SE", "z_SE"), row.names = c(NA, 
-4L), class = "data.frame")
zlim = c(-1, 2)

cloud(z~x+y, data = data, panel.3d.cloud=panel.3dbars, col.facet ='grey',
      xbase=0.4, ybase=0.4, scales=list(arrows=FALSE, col="black"),
      par.settings = list(axis.line = list(col = "transparent"))
      , zlim = zlim) +
    as.layer(cloud(
        z_SE~x+y, data = data, col ='black',
        par.settings = list(axis.line = list(col = "transparent"))
        , zlim = zlim, xlab = NULL, ylab = NULL, zlab = NULL
    )) +
    as.layer(cloud(
        value~x+y, data = bind_rows(select(data, x, y), gather((data %>% select(x, y, z, z_SE))[1,], z, z_SE, key = "key", value = "value"))
        , col ='black', panel.3d.cloud = panel.3dscatter, type = "l"
        , par.settings = list(axis.line = list(col = "transparent"))
        , zlim = zlim, xlab = NULL, ylab = NULL, zlab = NULL
    )) +
    as.layer(cloud(
        value~x+y, data = bind_rows(select(data, x, y), gather((data %>% select(x, y, z, z_SE))[2,], z, z_SE, key = "key", value = "value"))
        , col ='black', panel.3d.cloud = panel.3dscatter, type = "l"
        , par.settings = list(axis.line = list(col = "transparent"))
        , zlim = zlim, xlab = NULL, ylab = NULL, zlab = NULL
    )) +
    as.layer(cloud(
        value~x+y, data = bind_rows(select(data, x, y), gather((data %>% select(x, y, z, z_SE))[3,], z, z_SE, key = "key", value = "value"))
        , col ='black', panel.3d.cloud = panel.3dscatter, type = "l"
        , par.settings = list(axis.line = list(col = "transparent"))
        , zlim = zlim, xlab = NULL, ylab = NULL, zlab = NULL
    )) +
    as.layer(cloud(
        value~x+y, data = bind_rows(select(data, x, y), gather((data %>% select(x, y, z, z_SE))[4,], z, z_SE, key = "key", value = "value"))
        , col ='black', panel.3d.cloud = panel.3dscatter, type = "l"
        , par.settings = list(axis.line = list(col = "transparent"))
        , zlim = zlim, xlab = NULL, ylab = NULL, zlab = NULL
    ))

enter image description here

如果您知道任何其他解决方案,请告诉我。

感谢。