3

Just run the follwing code. I want to display a coordinate grid, but nothing happens:

df_runtime <- data.frame(x = c(0L, 20L), 
                         y = c(0L, 10L), 
                         z = c(0L, 50L), stringsAsFactors = FALSE)

car::scatter3d(x = df_runtime$x,
               y = df_runtime$y,
               z = df_runtime$z,
               xlab = "x", ylab = "x", zlab = "z", 
               surface = FALSE, grid = TRUE)

From the docs ??car::scatter3d I realized that

plot grid lines on the regression surface(s) (TRUE or FALSE).

Thus, the grid parameter is not what I was looking for. Is there a way to get a coordinate grid? To me, this is really useful as a guide for the eye.


Edit after Carles input:

I would like to keep the interactive graph - that's why I'm looking for car::scatter3d solution. If you don't need this, a combination of scatterplot3d and FactoClass is really nice. The following works in a non-interactive way:

scatterplot3d::scatterplot3d(
  df_runtime$x,
  df_runtime$y,
  df_runtime$z,
  color = "blue", pch = 19, # filled blue circles
  # type = "h",             # lines to the horizontal plane
  main = "Title",
  xlab = "x",
  ylab = "y",
  zlab = "z",
  angle = 35,
  grid = FALSE)
FactoClass::addgrids3d(df_runtime$x,
                       df_runtime$y,
                       df_runtime$z,
                       angle = 35,
                       grid = c("xy", "xz", "yz"))
Christoph
  • 6,841
  • 4
  • 37
  • 89
  • It seems that this function does not allow for a grid. However, you might be able to modify the function created by @agstudy here https://stackoverflow.com/questions/20448539/add-yz-and-xz-grid-to-scatterplot3d for another 3d graphing function – prosoitos Nov 18 '18 at 19:27

2 Answers2

4

If you want an interactive plot with a grid, plotly is another solution:

df_runtime <- data.frame(x = c(0L, 20L), 
                         y = c(0L, 10L), 
                         z = c(0L, 50L), stringsAsFactors = FALSE)

plotly::plot_ly(df_runtime, 
                     x = ~x, 
                     y = ~y, 
                     z = ~z,
                type = 'scatter3d',
                mode = 'markers')

Plotly Graph

Chris
  • 6,302
  • 1
  • 27
  • 54
1

To me it does not work. However, you can use some other package such as library("scatterplot3d"). I have just put more points and it works:

df_runtime <- structure(list(n_legs_array = rnorm(100,0,10), 
                             n_vehicles_array = rnorm(100,0,10), 
                             t = rnorm(100,0,10)), 
                        .Names = c("n_legs_array", "n_vehicles_array", "t"), 
                        row.names = c(1L, 2L), 
                        class = "data.frame")
library("scatterplot3d")

scatterplot3d(x = df_runtime$n_legs_array,
               y = df_runtime$t/60, # minutes
               z = df_runtime$n_vehicles_array,
               xlab = "n_legs", ylab = "time [min]", zlab = "n_vehicles", 
                grid = TRUE,box = FALSE,
               color =   "#56B4E9")
Carles
  • 2,731
  • 14
  • 25
  • Doesn not help. See my edit. Do you really have a plot with grid? – Christoph Jun 27 '18 at 15:02
  • It does not look like it works. If you want a grid, you can use another package like `scatterplot3d`. http://www.sthda.com/english/wiki/scatterplot3d-3d-graphics-r-software-and-data-visualization – Carles Jun 27 '18 at 16:23
  • 1
    Not a solution, but +1 because you made me read the docs twice ;-) see my edit... – Christoph Jun 27 '18 at 16:40
  • I see. I spend some time trying it, but I think there is some bug – Carles Jun 27 '18 at 21:27