2016-05-05 70 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)。你可以嘗試沒有顏色,只有線爲最小和最大。

相關問題