Skip to contents

Creates general-purpose 3D scatter plots using plotly. Unlike DimPlot's built-in 3D mode (which only works with dimension reduction data), this accepts any x/y/z columns with color and size mappings.

Usage

Scatter3D(
  data,
  x,
  y,
  z,
  color_by = NULL,
  color_name = NULL,
  size_by = NULL,
  size_name = NULL,
  hover_text = NULL,
  pt_alpha = 0.8,
  palette = "forge",
  palcolor = NULL,
  title = NULL,
  xlab = NULL,
  ylab = NULL,
  zlab = NULL,
  width = NULL,
  height = NULL,
  legend.position = "right",
  seed = 8525,
  ...
)

Arguments

data

A data frame containing the data to plot

x, y, z

Column names for the three axes.

color_by

Column for point coloring (categorical or continuous).

color_name

Legend title for color.

size_by

Column for point sizing, or a numeric value.

size_name

Legend title for size.

hover_text

Column for hover tooltip text.

pt_alpha

Point opacity.

palette

Color palette name

palcolor

Custom colors for palette

title

Plot title

xlab

X-axis label

ylab

Y-axis label

zlab

Z-axis label (for 3D and ternary plots)

width, height

Plot dimensions in pixels.

legend.position

Legend position: "none", "left", "right", "bottom", "top"

seed

Random seed for reproducibility

...

Additional arguments.

Value

A plotly object

See also

Other 3d-interactive-plots: Surface3D()

Examples

# \donttest{
set.seed(42)
data <- data.frame(
  x = rnorm(100), y = rnorm(100), z = rnorm(100),
  group = sample(c("A", "B", "C"), 100, replace = TRUE),
  value = runif(100)
)
Scatter3D(data, x = "x", y = "y", z = "z", color_by = "group")
Scatter3D(data, x = "x", y = "y", z = "z", color_by = "value")
# }