x <- c(1, 2, 3, 4, 5)
y <- c(2, 3, 5, 4, 7)
z <- c(10, 8, 12, 9, 15)
categories <- c("A", "B", "A", "C", "B")
category_colors <- c("red", "blue", "green")
plot_ly(x = x, y = y, z = z, type = 'scatter3d', mode = 'markers',
marker = list(color = factor(categories, levels = unique(categories),
labels = category_colors)))