关闭R

时间:2018-01-20 17:58:28

标签: r plotly scatter-plot r-plotly

enter image description here 当您将鼠标悬停在标记上时,在(在API中)调用哪条线从标记延伸到相应的轴? 有办法解决这些问题吗?

library(plotly)

itemName = c("Alpha", "Bravo", "Charley", "Delta", "Echo", "Foxtrot") 
security = c(0.8583241, 0.7516891, 0.5390520, 0.4569594, 0.3228843, 0.1722286) 
miniX = c(-885.108, -1030.000, -805.889, -695.755, -887.871, -640.986) 
miniY   = c(-445.135, -298.563, -797.709, -806.598, -963.091, -1010)
miniZ   = c(423.694, 417.075, 616.456, 571.223, 575.304, 412.72)

df = data.frame(itemName, security, miniX, miniY, miniZ)

# set a range of colors
colors <- c('#f42f28', '#f2e30e', '#2d9b37', '#31a6f3') 


######### set up 3d scatter plot  #########
p1 <- plot_ly(df, 
             x = miniX, 
             y = miniY, 
             z = miniZ, 
             mode = "markers", 
             size = security, 
             color = security, 
             colors = colors,
             marker = list(symbol = 'circle', sizemode = 'diameter'), sizes = c(10, 20),
             text = paste('Item:', itemName, '<br>Security:', security),
             hoverinfo = "none"
) %>%
  add_markers() %>%
  layout(title = 'Locales',
         scene = list(xaxis = list(title = '', autorange = TRUE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE),
                      yaxis = list(title = '', autorange = TRUE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE),
                      zaxis = list(title = '', autorange = TRUE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE)
         )
  )

# Output the plot
p1

1 个答案:

答案 0 :(得分:2)

这里的正确答案是在场景列表中设置showspikes = FALSE:

 scene = list(xaxis = list(title = '', autorange = TRUE, showspikes = FALSE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE),
              yaxis = list(title = '', autorange = TRUE, showspikes = FALSE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE),
              zaxis = list(title = '', autorange = TRUE, showspikes = FALSE, showgrid = FALSE, zeroline = FALSE, showline = FALSE, autotick = TRUE, ticks = '', showticklabels = FALSE)

showpikes未显示在自动填充中,也未在3d散点图部分的文档中显示。