1
votes

I have created the following 3d scatter plot using plotly in R. For this I used the following code The data setTxy, just contains the x,y,z coordinates of each marker and a value between 0-1.5 for each coordinate point (in a column with name vectorM)

figfactor<- plot_ly(setTxy, x=~xplot,y=~yplot*-1,z=(~zplot*-1),
             type="scatter3d",mode="markers",
             marker=list(color=~vectorM,
                     colorscale=c("rgb(244, 244, 244)","rgb(65, 65, 65)"),
                     showscale=TRUE,
                     line=list(width=2,color='DarkSlateGrey')))
        
figfactor <- figfactor %>% add_markers()
figfactor <- figfactor %>% layout(scene = list(xaxis = list(title = 'x-value [mm]'),
                                   yaxis = list(title = 'y-value [mm]'),
                                   zaxis = list(title = 'z-value [mm]')),
                      annotations = list(
                        x = 1.06,
                        y = 1.03,
                        text = 'factor',
                        xref = 'paper',
                        yref = 'paper',
                        showarrow = FALSE
                      ))
figfactor

3d scatterplot

I thought I changed all colors to grey , but there is still collor in the plot. How can I change this? Further: -why is the scaling not in grey; and how can I create this? -how can I outline "factor"above the scale on the right -why do I have 'trace 0'and 'trace 1'?

How can I draw two circles in this graph, either by drawing into the graph or by using the formula of a circle?

Thanks

1
Your question is almost unreadable. Please edit the question and fix any missing code sections.Oliver
question is edittedJan
Much better. Answer has been provided. :-)Oliver

1 Answers

1
votes

From the documentation scatter-marker-color the problem is that the colours are given in the wrong format. Note the part marked in bold below

Sets the colorscale. Has an effect only if in marker.line.coloris set to a numerical array. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required. For example, [[0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']]. To control the bounds of the colorscale in color space, usemarker.line.cmin and marker.line.cmax. Alternatively, colorscale may be a palette name string of the following list:

  • Greys, YlGnBu, Greens, YlOrRd, Bluered, RdBu, Reds, Blues, Picnic, Rainbow, Portland, Jet, Hot, Blackbody, Earth, Electric, Viridis, Cividis.

In R an array is either created using array or as a list of lists (or list of vectors). As such we can obtain the fully gray colouring in two ways:

  1. Setting colourscale = 'Greys'
  2. Remapping your vector to a list of vectors.

Using the mtcars data as an example this could be done as

data(mtcars)
library(plotly)
plot_ly(mtcars, x = ~hp, y = ~cyl, z = ~mpg,
       type = 'scatter3d', mode = 'markers',
       marker = list(color = ~ hp,
                     # Use either a named palette in the above list:
                     #colorscale = 'Greys',
                     # Or use a list of vector scales.
                     colorscale = list(c(0, rgb(55, 55, 55, max = 255)), 
                                       c(1, rgb(244, 244, 244, max = 255))),
                     showscale = TRUE))

Note that the line argument is unnecessary unless you want specifically to add lines between points, and that the order of your list does matter (eg. c(1, ...) should always come after c(0, ...)).