3

只需运行以下代码。我想显示一个坐标网格,但没有任何反应:

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)

从文档??car::scatter3d中我意识到

在回归曲面上绘制网格线(真或假)。

因此,该grid参数不是我想要的。有没有办法获得坐标网格?对我来说,这对眼睛的指导非常有用。


在 Carles 输入后编辑

我想保留交互式图表 - 这就是我正在寻找car::scatter3d解决方案的原因。如果你不需要这个,scatterplot3d和的组合FactoClass真的很好。以下以非交互方式工作:

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

2 回答 2

4

如果你想要一个带有网格的交互式绘图,plotly是另一种解决方案:

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

绘图图

于 2018-11-14T21:04:14.787 回答
1

对我来说它不起作用。但是,您可以使用其他一些包,例如library("scatterplot3d"). 我刚刚提出了更多观点并且它有效:

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")
于 2018-06-27T12:46:36.970 回答