[英]Add Annotation to 3D Scatterplot in Plotly
我是這個舞台的新手,希望得到一些幫助。 我剛剛開始使用Plotly並且正在使用它來構建一個非常基本的3D散點圖,它可以模擬一些貨架以及哪些物品在哪里。 當我構建“架子”和情節渲染時,我想在文本中添加一個注釋,指示我正在查看哪些架子。
這是我的程序的當前輸出, 這是我想要做的
我已經嘗試查看文檔並嘗試添加注釋(就像我對2D模擬一樣)並且在代碼編譯時,文本沒有顯示出來。
p <- plot_ly(all, x = X, y = Y, z = Z,
text = paste0("Candy: ", SKU,"; QTY: ", Qty),
color = OccupiedPct,
colors = cols,
hoverinfo = "text",
type = "scatter3d", mode = "markers") %>%
layout(
title = "Shelves"
)
sub <- list(
x = 3,
y = 2,
z = 0,
text = "Shelf1",
xref = "x",
yref = "y",
zref = "z",
showarrow = FALSE
)
p %>%
layout(annotations = sub)
先感謝您! 麥克風
#更新感謝@MLavoie的回答並抱歉排除了可重現的數據集。 不幸的是,我無法復制你所做的事情。 我注意到你的情節中的z軸設置為零,我試圖重置我的沒有成功。 然而,即使將點調整到繪圖范圍內,我仍然無法讓它顯示出來。 這是我得到的情節: 當我運行此代碼時
R version 3.2.1 (2015-06-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] plotly_2.0.16 ggplot2_2.0.0
loaded via a namespace (and not attached):
[1] Rcpp_0.12.3 digest_0.6.9 grid_3.2.1 plyr_1.8.3 R6_2.1.2 jsonlite_0.9.19 gtable_0.1.2 magrittr_1.5 scales_0.3.0 httr_1.1.0
[11] viridis_0.3.2 tools_3.2.1 htmlwidgets_0.5 munsell_0.4.2 yaml_2.1.13 base64enc_0.1-3 colorspace_1.2-6 htmltools_0.3 gridExtra_2.0.0
為了完整性,這是我的會話信息:
R version 3.2.1 (2015-06-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 8 x64 (build 9200) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] plotly_2.0.16 ggplot2_2.0.0 loaded via a namespace (and not attached): [1] Rcpp_0.12.3 digest_0.6.9 grid_3.2.1 plyr_1.8.3 R6_2.1.2 jsonlite_0.9.19 gtable_0.1.2 magrittr_1.5 scales_0.3.0 httr_1.1.0 [11] viridis_0.3.2 tools_3.2.1 htmlwidgets_0.5 munsell_0.4.2 yaml_2.1.13 base64enc_0.1-3 colorspace_1.2-6 htmltools_0.3 gridExtra_2.0.0
再次感謝!
使用虹膜數據集(您沒有提供可重現的示例),您可以嘗試:
set.seed(100)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(d, x = carat, y = price, z=depth, text = paste("Clarity: ", clarity),
type="scatter3d", mode="markers")
p %>%
add_trace(x = 2.5, y = 5000, z = 0, type = "scatter3d", text = "test", mode = "text") %>%
add_trace(x = 2.5, y = 15000, z = 0, type = "scatter3d", text = "test", mode = "text") %>%
layout(showlegend = FALSE)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.