简体   繁体   English

如何在car :: scatter3d图中显示坐标网格

[英]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 从文档??car::scatter3d我意识到了

plot grid lines on the regression surface(s) (TRUE or FALSE). 绘制回归曲面上的网格线(TRUE或FALSE)。

Thus, the grid parameter is not what I was looking for. 因此, grid参数不是我想要的。 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 : 在Carles输入后编辑

I would like to keep the interactive graph - that's why I'm looking for car::scatter3d solution. 我想保留交互式图表 - 这就是我正在寻找car::scatter3d解决方案的原因。 If you don't need this, a combination of scatterplot3d and FactoClass is really nice. 如果您不需要这些的组合scatterplot3dFactoClass是非常好的。 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"))

If you want an interactive plot with a grid, plotly is another solution: 如果你想与电网的互动情节, 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')

Plotly Graph

To me it does not work. 对我来说它不起作用。 However, you can use some other package such as library("scatterplot3d") . 但是,您可以使用其他一些包,例如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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM