如何在 car::scatter3d 图中显示坐标网格
How to show a coordinate grid in car::scatter3d plot
只需运行下面的代码。我想显示一个坐标网格,但没有任何反应:
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
我意识到
plot grid lines on the regression surface(s) (TRUE or FALSE).
因此,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"))
对我来说它不起作用。但是,您可以使用其他一些包,例如 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")
如果你想要一个带有网格的交互式绘图,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')
只需运行下面的代码。我想显示一个坐标网格,但没有任何反应:
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
我意识到
plot grid lines on the regression surface(s) (TRUE or FALSE).
因此,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"))
对我来说它不起作用。但是,您可以使用其他一些包,例如 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")
如果你想要一个带有网格的交互式绘图,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')