Christoph
Christoph

Reputation: 7063

How to show a coordinate grid in car::scatter3d plot

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"))

Upvotes: 3

Views: 438

Answers (2)

Chris
Chris

Reputation: 6372

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

Upvotes: 4

Carles
Carles

Reputation: 2829

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")

Upvotes: 1

Related Questions