我使用plotly创建了一个3D散点图,并将回归平面建模为数据的子集,最后将其添加到所有点以实现更好的可视化。
如何更改添加的回归平面的色阶,使其 (i) 无(只有黑色平面),或 (ii) 显示模型在空间中给定点的标准误差?
I had a dataset http://www.geochem.hu/people/hatvani/mdata.csv mdata2
4 个变量,我必须在 3d 中绘制(Window
, Unc
, variable
),第四维是value
。
我创建了一个数据的子集 http://www.geochem.hu/people/hatvani/mdata2.csv mdata3
并在其上建模一个线性回归平面,将该平面扩展到整个数据集的维度。
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
我用 3D 方式绘制了整个数据集plotly
并向其中添加回归平面。
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
并在上面看到了情节link http://www.geochem.hu/people/hatvani/bemutato.html
and here http://www.geochem.hu/people/hatvani/newplot.png.
我本来希望看到没有任何着色的回归平面,特别是因为它也弄乱了 3d 散点图的比例。
Moreover, regarding the scatterplot, is there any possibility to create breaks in the color scale as in this 2D ggplot plot http://www.geochem.hu/people/hatvani/Rplot.png,
which shows just onr Period slice of the 3D plot above?
感谢您的任何帮助。
Ps.:以下警告是由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'