如何使scatter3d看起来像3d中的密度图?
我正在尝试在plot_ly scatter3d绘图中设置不透明度(或其他一些变量),以使用绘图中每个点的值,其值来自数据框中的列。这是为了创建一种三维散射密度图。 在这种情况下,不透明度列包含随机值,但如果事实证明这是可能的,我想在附近点的数量较高时使点不透明,而在相对隔离时使点不透明。 在保持scatter3d样式的同时使其看起来像密度图的另一种方法也很好。
我在plot_ly代码中尝试使用不透明度或alpha值的尝试失败了,我找不到一个有效的例子。
可以从此处下载数据集:file
library(shiny)
library(plotly)
library(data.table)
mydf <- read.csv("myshowdf.csv")
ui <- fluidPage(
plotlyOutput('scatter', width = 800, height = 600)
)
server <- function(input, output, session) {
output$scatter <- renderPlotly({
ppl <- plot_ly(mydf, x = ~FL.Red.Range, y = ~FL.Yellow.Range, z = ~SWS.Length, mode = 'markers',
color = ~sub.flow.FP1, marker = list(size = 4, opacity =mydf$opacity),
colors = c('blue', 'green', 'red', 'yellow'),
type = 'scatter3d', source = 'scatter') %>%
layout( autosize = F,
margin = list(l = 40, r = 20, b = 20, t = 40, pad = 4)
)
ppl$elementId <- NULL
ppl
})
}
shinyApp(ui = ui, server = server)