andemexoax
andemexoax

Reputation: 323

3D scatter plot using symbols for markers with plotly in R

I am unable to get all my desired symbols to appear with a 3D scatter plot in R using the plotly package. I know that I am stretching what is distinguishable (for example color palette is greater than n=8 and symbols are greater than n=6, R throws warnings), and that is okay for my exploratory purposes, but is there a way to force code my desired marker styles?. I've tried to follow the answer to this question but it didn't work in my case so I've tried extracting the actual symbols available and hard coding them. What I'd really like is both color and shape to vary by the categorical variable 'species'.

Here is my fake data, that I am trying to mimic the results of a PCA:

df <- data.frame(my_x=rnorm(n=58,sd=30), 
   my_y=rnorm(n=58,sd=20),
   my_z=rnorm(n=58,sd=35),
   species=rep(letters,times=3, length.out=58))

#extracting possible symbols from plotly
vals <- schema(F)$traces$scatter$attributes$marker$symbol$values
vals <- grep("-", vals, value = T)
vals1 <- rep(vals[sample(x=c(1:length(vals)),size=58, replace = FALSE)

plot_ly() %>%
  add_trace(x= ~df$my_x, y= ~df$my_y, z= ~df$my_z,
            type="scatter3d", mode="markers", color=~df$species, symbol= ~I(vals1),
            marker = list(opacity = 0.7))

3d scatter plot

plotly version 4.9.3 with R version 4.0.3 in RStudio Version 1.4.1103 on Windows 10.

Upvotes: 1

Views: 1223

Answers (0)

Related Questions