2016-05-05 156 views
0

我试图找到一种方法将+/-标准误差线添加到latticeExtra中使用云功能的3D条形图中。我知道3D地块并不是可视化数据的最佳方式,但我的主管已经要求我将它们放在一起看看它的外观。我花了几天的时间搜索本网站和其他人的帖子,找不到答案。它在3D空间中甚至可行吗?将+/-标准误差线添加到latticeExtra的3D条形图中

我的数据是在不同的笼养处理中,从3种不同老化组合的3种不同尺寸类别的x物种覆盖率。我按尺寸(sml,med,lg)和年龄/笼子(4,8,12周;笼子,无笼子)进行颜色编码。

我的代码是:

library(latticeExtra) 

cloud(Sol.Ascid ~ AgeCage + Size, dd, 
    panel.3d.cloud = panel.3dbars, 
    col.facet = level.colors(dd$CageSize, at = 0:6, 
          col.regions = myColoursTrans, 
          colors = TRUE), 
    xbase = 0.6, ybase = 0.6, zlim = c(0, 6), 
    xlab = NULL, ylab = NULL, zlab = NULL, main = "Solitary Ascidians", 
    lty = 0, #got rid of lines since they're not right.. not sure why.. 
    screen = list(z = 50, x = -50, y = 0), 
    scales = list(arrows = FALSE, col = 1), 
    par.settings = list(axis.line = list(col = "transparent"))) 

DD是均值和对于所有种类的标准误差的数据帧。

3D bar plot from the code above

我道歉,如果这是一个愚蠢的问题,我是新来的R和这个论坛。

问候,

DaveTurek - 为myColoursTrans(下图)的代码,做我只是复制和数据粘贴到该窗口(看起来有点乱)?

structure(list(AgeCage = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 
3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 6L, 6L, 6L), .Label = c("4 NC", 
"4 C", "8 NC", "8 C", "12 NC", "12 C"), class = "factor"), Size = structure(c(1L, 
2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 
3L), .Label = c("Small", "Medium", "Large"), class = "factor"), 
CageSize = c(2, 4, 6, 1, 3, 5, 2, 4, 6, 1, 3, 5, 2, 4, 6, 
1, 3, 5), Sol.Ascid = c(0, 0, 0, 0.1, 0, 0, 0, 0, 0, 0.2, 
0.2, 0.5, 0, 0, 0.3, 0.2, 0.9, 4.7), Sol.Ascid.se = c(0, 
0, 0, 0.1, 0, 0, 0, 0, 0, 0.133333333333333, 0.133333333333333, 
0.30731814857643, 0, 0, 0.152752523165195, 0.133333333333333, 
0.406885187191123, 1.19303534454489), Barnacles = c(0.5, 
0.2, 0, 0.5, 0.3, 0.4, 0.4, 0.1, 0, 0.7, 0.5, 0, 0.2, 0.5, 
0.9, 0.4, 0.2, 0.8), Barnacles.se = c(0.30731814857643, 0.133333333333333, 
0, 0.341565025531987, 0.3, 0.4, 0.221108319357027, 0.1, 0, 
0.395811402901264, 0.223606797749979, 0, 0.2, 0.223606797749979, 
0.433333333333333, 0.4, 0.133333333333333, 0.416333199893227 
), Dead.Barnacles = c(0, 0.1, 0, 0.7, 0.2, 0, 0.9, 3.1, 0.5, 
4.4, 7.7, 1.9, 1.55, 3.35, 6.4, 1.7, 2.7, 8.3), Dead.Barnacles.se = c(0, 
0.1, 0, 0.334995854037363, 0.2, 0, 0.406885187191123, 1.19675487140108, 
0.401386485959743, 1.70749979664876, 1.9035055380359, 0.737111479583199, 
0.216666666666667, 1.39851111305321, 1.38403596613511, 0.7, 
0.989388138643722, 3.33683149776018), Barnacle.Scar = c(1.3, 
0.3, 0, 0, 0, 0, 3.3, 18, 6.9, 0, 0.3, 0.1, 1.7, 1.9, 6, 
0, 0.3, 0), Barnacle.Scar.se = c(0.448454134902457, 0.213437474581095, 
0, 0, 0, 0, 0.7, 2.67083008320135, 1.8405916923038, 0, 0.3, 
0.1, 0.53851648071345, 0.706320670013903, 1.25609624542778, 
0, 0.3, 0), Sponges = c(0, 0, 0, 0.1, 0, 0, 0.1, 0.3, 0.1, 
0, 0.5, 1.4, 0, 0.6, 1.3, 0.3, 1.2, 2.5), Sponges.se = c(0, 
0, 0, 0.1, 0, 0, 0.1, 0.152752523165195, 0.1, 0, 0.268741924943285, 
0.561743318211757, 0, 0.221108319357027, 0.53851648071345, 
0.3, 0.3590109871423, 0.819891591749923), Serpulids = c(0.8, 
0.3, 0, 0.9, 0.1, 0, 1.7, 2.4, 0.95, 0.9, 2.3, 1.4, 1, 2.4, 
1.5, 1.5, 2.1, 1.9), Serpulids.se = c(0.32659863237109, 0.213437474581095, 
0, 0.585946527708232, 0.1, 0, 0.683942817622773, 0.956846672960488, 
0.320156211871642, 0.31446603773522, 0.683942817622773, 0.791622805802528, 
0.298142396999972, 0.581186525805423, 0.5, 1.17615191762516, 
0.674124947205223, 0.706320670013903), Serpulid.Scars = c(1.7, 
0.5, 0, 0, 0, 0, 0.9, 1.7, 0.4, 0, 0, 0, 1.2, 1.5, 1.4, 0, 
0, 0), Serpulid.Scars.se = c(0.472581562625261, 0.401386485959743, 
0, 0, 0, 0, 0.406885187191123, 0.517472489875334, 0.221108319357027, 
0, 0, 0, 0.32659863237109, 0.30731814857643, 0.42687494916219, 
0, 0, 0)), .Names = c("AgeCage", "Size", "CageSize", "Sol.Ascid", 
"Sol.Ascid.se", "Barnacles", "Barnacles.se", "Dead.Barnacles", 
"Dead.Barnacles.se", "Barnacle.Scar", "Barnacle.Scar.se", "Sponges", 
"Sponges.se", "Serpulids", "Serpulids.se", "Serpulid.Scars", 
"Serpulid.Scars.se"), row.names = c(NA, -18L), class = "data.frame") 

library(RColorBrewer)     # load some colour palettes 
display.brewer.all()     # check them out visually 
myColours <- brewer.pal(6, "Paired") # choose the first 6 from the one with paired colours 

## function to add transparency to colours 
add.alpha <- function(col, alpha=1){ 
    apply(sapply(col, col2rgb)/255, 2, 
     function(x) 
     rgb(x[1], x[2], x[3], alpha=alpha)) 
} 

myColoursTrans <- add.alpha(c(myColours), alpha = 0.7) 
+0

您应该提供您的数据。从'dput(dd)'粘贴输出。我假设它不是太长。还应该提供'myColoursTrans'。 – DaveTurek

+0

添加了数据,希望您在我每次编辑帖子时都没有收到通知! – DBolt

+0

不,刚通知您的评论。也许是杂乱的,但'dd < - 结构(列表(AgeCage ...'给了我们你的数据,所以我们可以重现你的情节,没有承诺,但我会看看我是否可以尝试一些想法。 – DaveTurek

回答

0

您可以尝试使用latticeExtra的图层。 定义上限值和下限值。

dd = within(dd, { 
    SAmax = Sol.Ascid+Sol.Ascid.se 
    SAmin = Sol.Ascid-Sol.Ascid.se 
    }) 

定义单独的颜色。

myColoursTrans1 <- add.alpha(c(myColours), alpha = 0.1) 
myColoursTrans2 <- add.alpha(c(myColours), alpha = 0.3) 
myColoursTrans3 <- add.alpha(c(myColours), alpha = 0.9) 

然后建立三层。

cloud(SAmax ~ AgeCage + Size, dd, 
    panel.3d.cloud = panel.3dbars, 
    col.facet = level.colors(dd$CageSize, at = 0:6, 
          col.regions = myColoursTrans1, 
          colors = TRUE), 
    xbase = 0.6, ybase = 0.6, zlim = c(0, 6), 
    xlab = NULL, ylab = NULL, zlab = NULL, main = "Solitary Ascidians", 
# lty = 0, #got rid of lines since they're not right.. not sure why.. 
    screen = list(z = 50, x = -50, y = 0), 
    scales = list(arrows = FALSE, col = 1), 
    par.settings = list(axis.line = list(col = "transparent"))) + 

    as.layer(cloud(Sol.Ascid ~ AgeCage + Size, dd, 
    panel.3d.cloud = panel.3dbars, 
    col.facet = level.colors(dd$CageSize, at = 0:6, 
          col.regions = myColoursTrans2, 
          colors = TRUE), 
    xlab = NULL, ylab = NULL, zlab = NULL, main = "", 
    xbase = 0.6, ybase = 0.6, zlim = c(0, 6),#lty=0, 
    screen = list(z = 50, x = -50, y = 0))) + 

    as.layer(cloud(SAmin ~ AgeCage + Size, dd, 
    panel.3d.cloud = panel.3dbars, 
    col.facet = level.colors(dd$CageSize, at = 0:6, 
          col.regions = myColoursTrans3, 
          colors = TRUE), 
    xlab = NULL, ylab = NULL, zlab = NULL, main = "", 
    xbase = 0.6, ybase = 0.6, zlim = c(0, 6),#lty=0, 
    screen = list(z = 50, x = -50, y = 0))) 

上面不重合(见中12C)。你可以尝试没有颜色,只有线为最小和最大。

相关问题