Hello,
I am trying to combine scatter3d and mesh3d traces into a single plot with Ploty R v4.9.0. The issues Im running into is A) the hoverinfo for my points does not display over the mesh3d trace and B) creating a button to turn the mesh3d trace on/off actually removes points from the plot for some reason.
I have searched for examples and found that this example, https://plot.ly/python/alpha-shapes/#plotly-mesh3d, shows that the mesh3d doesnt cause hoverinfo over the points to disappear. There is no specific layout attributes changed, so I am not sure why drawing the mesh3d in my plot essentially removes the hover info on a point inside the mesh3d convex hull.
I have tried all the settings under hoverinfo, for all, skip, and and none without any way working.
Finally, trying to create a button to turn on/off the mesh3d trace actaully removes the points that fall within the mesh3d convex hull from the plot. Is there some way to prevent this from happening? A reproducible example of code and data are below.
Thanks in advance,
Jenny
CODE:
# https://plot.ly/python/alpha-shapes/#plotly-mesh3d
# https://stackoverflow.com/questions/50412858/plotting-ellipse3d-in-r-plotly-with-surface-ellipse
updatemenus <- list(
list(
active = -1,
type= 'buttons',
buttons = list(
list(
label = "Ellipsoid",
method = "update",
args = list(list(visible = c(TRUE, TRUE)))),
list(
label = "No Ellipsoid",
method = "update",
args = list(list(visible = c(TRUE, FALSE)))))
)
)
example_p <- plot_ly() %>%
#plot diagnostic and normal samples
add_trace(data=df,
x = ~x, y = ~y, z = ~z,
color = ~Group,
type='scatter3d',
mode='markers',
showlegend=TRUE,
marker=list(size=2.5),
text=df$Group,
hoverinfo='text',
inherit = TRUE) %>%
#Add 3D mesh (convex hulls)
add_trace(x=coords$x,
y=coords$y,
z=coords$z,
type="mesh3d",
alphahull=0, #*>0*, the alpha-shape algorithm is used, If *0*, the convex-hull algorithm is used
opacity=0.25,
showlegend=TRUE,
hoverinfo=list(extras="none",
flags="text"),
inherit = FALSE) %>% #try TRUE
layout(title=list(text="Example Mesh3D and Scatter3D",
font = list(color=rgb(1,1,1),
size=18)),
updatemenus=updatemenus)
example_p
DATA:
df = structure(list(x = c(5.86849670563368, -2.51378202454602, 1.6469491708704,
-2.20765301484607, 6.40576410173208, -2.00119241284032, 0.81138129291752,
5.47288057311659, -1.17449345934911, -1.48243022776696, -3.2063493238519,
-3.22436787161164, 7.98668634268574, -3.24612276437792, 8.65568032107949,
0.517694361599837, -3.60697132012569, -1.90695918094741, 4.39334696606732,
2.92383601892669, -1.56921041737926, -2.09170517744206, -3.22044776450979,
-1.97899788755705, -3.70964139622038), y = c(0.241077795458866,
2.21037541169333, -0.171944437975392, 1.27831182303403, 0.780702015147578,
1.63945927233085, 0.747434865572122, -0.0120158153792503, -1.53489467104739,
-5.20346553170559, -0.981154492460044, -0.988981586520343, 0.234168731010162,
-1.00965367225598, 0.0302401115607033, -1.27085817724873, -3.74710047165962,
-4.96540559835041, 0.216520419863618, -2.09250446060588, -4.76983115539762,
3.6809184514628, -0.995550535172484, 3.27972651946502, -3.82540405511137
), z = c(-2.77202525109703, -3.36674269756814, 1.39181461255231,
-3.60920615329835, -1.47173347958667, -3.38865677561506, -0.304960055969853,
-3.18943307295204, 0.279998733095555, -2.25026546434286, 0.847982149982344,
0.833825216947681, -1.98274802499484, 0.795916072613209, -2.11533113291302,
4.39476931838435, 1.00893174016458, -1.96544775868788, -4.54559229137462,
-2.18994003579537, -2.20642366273874, 3.40949358852021, 0.824081344490764,
3.06639935950504, 1.02059549822083), Sample = c("Sample_1", "Sample_2",
"Sample_3", "Sample_4", "Sample_5", "Sample_6", "Sample_7", "Sample_8",
"Sample_9", "Sample_10", "Sample_11", "Sample_12", "Sample_13",
"Sample_14", "Sample_15", "Sample_16", "Sample_17", "Sample_18",
"Sample_19", "Sample_20", "Sample_21", "Sample_22", "Sample_23",
"Sample_24", "Sample_25"), Group = c("C", "B", "B", "B", "B",
"C", "B", "A", "C", "B", "A", "A", "C", "B", "B", "C", "C", "B",
"B", "B", "B", "A", "B", "B", "B")), class = "data.frame", row.names = c(NA,
-25L))
coords=list(x = c(-1.77889018543796, -1.62660181810509, -1.62660181810509,
-3.09812127643566, -3.09812127643566, -1.76195432424378, -1.76195432424378,
-1.76195432424378, -1.76195432424378, -1.72079106448768, -1.58690781321767,
-1.58690781321767, -1.69713772094809, -1.69713772094809, -3.07383641748366,
-3.07383641748366, -1.60194541146394, -1.60194541146394, -1.60194541146394,
-1.75360460086882, -1.75360460086882, -1.95497647622602, -1.95497647622602,
-1.95497647622602, -2.16948057889859, -2.16948057889859, -2.16948057889859,
-2.16948057889859, -2.66274718064612, -2.66274718064612, -2.66274718064612,
-2.66274718064612, -3.11725888647611, -3.11725888647611, -3.11725888647611,
-1.969464238983, -1.969464238983, -1.969464238983, -1.76864046318633,
-1.76864046318633, -1.76864046318633, -2.95570724512092, -2.95570724512092,
-2.95570724512092, -2.95570724512092, -2.95570724512092, -3.0865049761747,
-3.0865049761747, -3.0865049761747, -1.87873070569909, -1.87873070569909,
-1.87873070569909, -1.87873070569909, -1.87873070569909), y = c(2.89063346215202,
3.08366853687939, 2.89063346215202, 2.52849277821416, 4.49053217660533,
4.49053217660533, 2.81097046244581, 4.49053217660533, 2.81097046244581,
3.49954297850659, 2.89063346215202, 3.6191751280364, 4.19032894848848,
4.49053217660533, 3.13839268456802, 3.13839268456802, 2.89063346215202,
4.44623600206336, 4.44623600206336, 4.3131617113742, 4.19032894848848,
3.45161531724094, 4.3131617113742, 4.3131617113742, 4.3131617113742,
4.3131617113742, 3.15284254333225, 3.2032637679732, 3.15284254333225,
3.59078422189249, 3.45161531724094, 3.59078422189249, 3.2032637679732,
3.15284254333225, 4.15847712251727, 4.3131617113742, 3.59078422189249,
3.59078422189249, 3.6191751280364, 3.59096006864121, 3.49954297850659,
3.4027001117787, 3.4027001117787, 3.08366853687939, 2.52849277821416,
3.15284254333225, 4.15847712251727, 3.16640823702633, 3.16640823702633,
3.59096006864121, 3.80659354387615, 3.80659354387615, 3.53975746982448,
3.53975746982448), z = c(3.58467520005205, 1.68306036105308,
3.58467520005205, 2.97316298272165, 1.68306036105308, 2.73255032949751,
1.97403378874058, 1.68306036105308, 1.68306036105308, 1.97403378874058,
2.73255032949751, 1.97403378874058, 2.73255032949751, 2.73255032949751,
2.97316298272165, 2.46707848441626, 2.73255032949751, 2.73255032949751,
1.97403378874058, 2.88196775560928, 3.1167351997011, 3.37247565429854,
3.37247565429854, 3.36496460251178, 2.46707848441626, 3.36496460251178,
3.36496460251178, 2.46707848441626, 3.36496460251178, 3.58467520005205,
3.37247565429854, 3.37247565429854, 2.97316298272165, 2.97316298272165,
2.71247332451114, 3.37247565429854, 3.37247565429854, 3.58467520005205,
3.2305414765963, 3.1167351997011, 3.58467520005205, 3.58467520005205,
3.13252127126462, 1.68306036105308, 2.97316298272165, 2.97316298272165,
3.13252127126462, 3.13252127126462, 2.71895418175431, 3.01597991282899,
3.01597991282899, 3.58467520005205, 3.58467520005205, 3.19730080507071
))