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

时间:2018-06-27 12:01:46

标签: r plot r-car

只需运行以下代码。我想显示一个坐标网格,但是什么也没发生:

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解决方案。如果您不需要这样做,那么scatterplot3dFactoClass的组合真的很不错。以下内容以非交互方式工作:

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

2 个答案:

答案 0 :(得分: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')

Plotly Graph

答案 1 :(得分: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")