在 R z 轴和同构中绘制 3D 散点图

plotly 3D scatterplot in R z axis and isomorphis

我正在尝试用 R 界面绘制 3D 散点图。 我的阴谋电话是:

p.sagittale<-plot_ly(data=filter(temp,tipo=='Caucasici'), x = ~coordX.Sagg , y = ~ coordY.Sagg, z = ~coordZ.Sagg,text = ~punti) %>% 
add_markers(color=~cluster) %>% 
layout(title = paste('Caucasici','Dente',i,'Sagittale'), xaxis = myaxis.list, yaxis = myaxis.list, zaxis=myaxis.list)

myaxis.list 定义如前:

myaxis.list<- list(
    zeroline = TRUE,
    showline = TRUE,
    mirror = "ticks",
    gridcolor = toRGB("gray50"),
    gridwidth = 2,
    zerolinecolor = toRGB("blue"),
    zerolinewidth = 4,
    linecolor = toRGB("black"),
    linewidth = 6,
    autotick = FALSE,
    ticks = "outside",
    tick0 = 0,
    dtick = 0.25
  )

我有两个问题: 1. 我收到警告:

"Warning message: 'layout' objects don't have these attributes: 'zaxis' Valid attributes include: 'font', 'title', 'titlefont', 'autosize', 'width', 'height', 'margin', 'paper_bgcolor', 'plot_bgcolor', 'separators', 'hidesources', 'smith', 'showlegend', 'dragmode', 'hovermode', 'xaxis', 'yaxis', 'scene', 'geo', 'legend', 'annotations', 'shapes', 'images', 'updatemenus', 'ternary', 'mapbox', 'radialaxis', 'angularaxis', 'direction', 'orientation', 'barmode', 'bargap', 'mapType'".

所以我的第一个问题是:如何设置z轴美学?

  1. 我想要一个同构图:刻度之间的间距相同,x、y、z 轴上的比例相同。我怎样才能得到这个?

在此先感谢您的支持

您需要将坐标轴包裹在 scene 中。

layout(scene = list(xaxis = myaxis.list,
                    yaxis = myaxis.list,
                    zaxis = myaxis.list),
       )

并通过 range.

指定轴的范围(即上限和下限)
myaxis.list<- list( 
  autorange = FALSE,
  range = c(-5, 5)
  [...]
) 

下图的完整代码

myaxis.list<- list( 
  zeroline = TRUE, 
  showline = TRUE, 
  mirror = "ticks", 
  gridcolor = toRGB("gray50"), 
  gridwidth = 2, 
  zerolinecolor = toRGB("blue"), 
  zerolinewidth = 4, 
  linecolor = toRGB("black"), 
  linewidth = 6, 
  autotick = FALSE, 
  ticks = "outside", 
  tick0 = 0, 
  dtick = 0.25,
  autorange = FALSE,
  range = c(-5, 5)
) 
p.sagittale<-plot_ly(data=filter(temp,tipo=='Caucasici'), x = ~coordX.Sagg , y = ~ coordY.Sagg, z = ~coordZ.Sagg,text = ~punti) %>%
add_markers(color=~cluster) %>%
layout(title = paste('Caucasici','Dente',"i",'Sagittale'), scene=list(xaxis = myaxis.list, yaxis = myaxis.list, zaxis=myaxis.list))