1

Currently my code looks like this:

library(plotly)

count = data.frame(
    row.names = c("Cell1", "Cell2", "Cell3", "Cell4", "Cell5", "Cell6"),
    Gene1 = c(10, 11, 8, 3, 2, 1),
    Gene2 = c(6, 4, 5, 3, 2.8, 1),
    Gene3 = c(12, 9, 10, 2.5, 1.3, 2),
    Gene4 = c(5, 7, 6, 2, 4, 7),
    
    stringsAsFactors = FALSE
)

threeD = plotly::plot_ly(
    data = count,
    x = ~Gene1,
    y = ~Gene2,
    z = ~Gene3,
    type = "scatter3d",
    mode = "markers",
    marker = list(size = 20),
    color = row.names(count)
)
threeD

This code generates following output: Plotly scatter3d plot

I would like to make the marker scale with the distance. So the markers nearest to "me" is bigger (Cell1 & Cell 2) and the markers far away appear smaller (Cell5 & Cell6). This would achieve a more realistic 3D feeling.

mariusr
  • 69
  • 6

1 Answers1

1

It's possible to make a kind of "bubble" plot by assigning a list of size to the markers so that they grow according to their respective value along the z-axis. The simplest way is to reuse the same data and apply some scaling function (product, log, etc.) as needed for example :

marker = list(size = c(12, 9, 10, 2.5, 1.3, 2)*5)

The problem is that if you change your point of view, the markers won't update magically for the intended 3D feeling.

You can also use color scaling by adding the colorscale property to the marker object, for example :

colorscale = c('#FFE1A1', '#683531')
EricLavault
  • 12,130
  • 3
  • 23
  • 45