## 13.8 Plotly 3D

• 3D: scatter, surface, mesh
plot_ly(type = "scatter3d",
mode = "markers",
swiss, x = swiss$Catholic, y = swiss$Education, z = swiss\$Fertility,
marker = list(color="black", size = 4),
text = row.names(swiss))
# ALSO TRY:  plot_ly(type = "surface", z = volcano)

### 13.8.1 3D Layout

• 3D Scene: Camera, Aspect Ratio
• 3D Axes: X, Y, Z
• Have to be specified in scene = list()

#### 13.8.1.1 3D Axes

p <- plot_ly(data = swiss, x = ~Catholic, y = ~Fertility, z = ~Education, type="scatter3d", mode = "markers")
layout(p,
scene = list(
yaxis = list(
showexponent = "all",
showticklabels = TRUE,
ticksuffix = "y",
color = "black",
titlefont = list(color = "red", family = "Times New Roman", size = 10),
title = "Fertility"
)

))

#### 13.8.1.2 3D Aspectmode and Camera

p <- plot_ly(data = swiss, x = ~Catholic, y = ~Fertility, z = ~Education, type="scatter3d", mode = "markers")
layout(p,
scene = list(
domain = list(y = c(0,1), x = c(0,1)),
aspectmode = "cube", # (enumerated: "auto" | "cube" | "data" | "manual" )
dragmode = "orbit", # (enumerated: "orbit" | "turntable" | "zoom" | "pan" )
camera = list( # Sets the (x,y,z) components of the 'eye' camera vector. This vector determines the view point about the origin of this scene.
eye = list(x = 1.25, y = 1.25, z = 1.25),

up = list(x = 0, y = 0, z = 1), # Sets the (x,y,z) components of the 'up' camera vector. This vector determines the up direction of this scene with respect to the page. The default is "{x: 0, y: 0, z: 1}" which means that the z axis points up.
# center = list(x = 0, y = 0, z = 1), # Sets the (x,y,z) components of the 'center' camera vector This vector determines the translation (x,y,z) space about the center of this scene. By default, there is no such translation.
#aspectratio = list(x = 1, y = 1, z = 1) ,
hovermode = "closest"
)),
height = 20
)