I have created a 3D scatter-plot with plotly and modelled a regression plane to a subset of the data and finally added it to all the points for better visualization. How can I change the color scale of the added regression plane, for it to have (i) none (just black plane), or to (ii) show the standard error the model has at a given point in space?
I had a dataset mdata2
of 4 variables ,which I had to plot in 3d (Window
, Unc
, variable
) with the 4th dimension being the value
.
I created a subset of the data mdata3
and modelled a linear regression plane onto it expanding the plane to the dimensions of the whole dataset.
per_lm <- lm(value ~ 0 + Unc + Window,data = mdata3)
#Graph Resolution (more important for more complex shapes)
graph_reso <- 5
#Setup Axis
axis_x <- seq(min(mdata2$Window), max(mdata2$Window), by = graph_reso)
axis_y <- seq(min(mdata2$Unc), max(mdata2$Unc), by = graph_reso)
#Sample points
per_lm_surface <- expand.grid(Window = axis_x,Unc = axis_y,KEEP.OUT.ATTRS = F)
per_lm_surface$value <- predict.lm(per_lm, newdata = per_lm_surface)
per_lm_surface <- acast(per_lm_surface, Unc ~ Window, value.var = "value") #y ~ x
I plotted the whole dataset in 3D with plotly
and added the regression plane to it.
library(reshape)
library(plotly)
fivepercent <- plot_ly(mdata2, x = ~Window, y = ~Unc, z = ~variable,
marker = list(color=~value, colorscale = "RdBu", showscale = TRUE)) %>%
add_markers() %>%
layout(scene = list(xaxis = list(title = 'Window'),
yaxis = list(title = 'Age uncertainty (yr)'),
zaxis = list(title = 'Period')),
annotations = list(
x = 1.13,
y = 1.05,
text = 'Spectral bias (yr)',
xref = 'paper',
yref = 'paper',
showarrow = FALSE))
fivepercent <- add_trace(p = fivepercent,
z = per_lm_surface,
x = axis_x,
y = axis_y,
type = "surface")
fivepercent
and got the plot seen on the link
and here.
I would have wanted to see the regression plane shown without any coloring especially because it messes up the scale of the 3d scatterplot as well.
Moreover, regarding the scatterplot, is there any possibility to create breaks in the color scale as in this 2D ggplot plot,
which shows just onr Period slice of the 3D plot above?
Thank you for any help.
Ps.: The following warning was produced by plotly
Warning message:
'surface' objects don't have these attributes: 'marker'
Valid attributes include:
'type', 'visible', 'showlegend', 'legendgroup', 'name', 'uid', 'ids', 'customdata', 'selectedpoints', 'hoverlabel', 'stream', 'uirevision', 'z', 'x', 'y', 'text', 'hovertext', 'hovertemplate', 'connectgaps', 'surfacecolor', 'cauto', 'cmin', 'cmax', 'cmid', 'colorscale',
'autocolorscale', 'reversescale', 'showscale', 'colorbar', 'contours', 'hidesurface', 'lightposition', 'lighting', 'opacity', '_deprecated', 'hoverinfo', 'xcalendar', 'ycalendar', 'zcalendar', 'scene', 'idssrc', 'customdatasrc', 'zsrc', 'xsrc', 'ysrc', 'textsrc', 'hovertextsrc', 'hovertemplatesrc', 'surfacecolorsrc', 'hoverinfosrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule', '_bbox'