我在R中有一个简单的数据框(c_X,c_Y,c_Z,time)。
我希望在时间等于零时首先在plot_ly中绘图。
然后我想要一个滑块从0到1,当滑块值为1时,该图显示x,y,z只有时间= 1的数据的散点图,当滑块值为0时,仅在列时间= 0时过滤数据。
test_x = rnorm(50)
test_y = rnorm(50)
test_z = rnorm(50)
time_0 = rep(0, 50)
df_list_1 = list('c_X' = test_x, 'c_Y' = test_y, 'c_Z' = test_z, 'time' = time_0)
df_1 = as.data.frame(df_list_1)
test_x2 = rnorm(50)
test_y2 = rnorm(50)
test_z2 = rnorm(50)
time_1 = rep(1, 50)
df_list_2 = list('c_X' = test_x2, 'c_Y' = test_y2, 'c_Z' = test_z2, 'time' = time_1)
df_2 = as.data.frame(df_list_2)
df_test = rbind(df_1, df_2)
p_all <- plot_ly(df_test, x = ~c_X, y = ~c_Y, z = ~c_Z)
p_all
答案 0 :(得分:1)
您可以将每个跟踪的TRUE
属性设置为FALSE
或test_x = rnorm(50)
test_y = rnorm(50)
test_z = rnorm(50)
time_0 = rep(0, 50)
df_list_1 = list('c_X' = test_x, 'c_Y' = test_y, 'c_Z' = test_z, 'time' = time_0)
df_1 = as.data.frame(df_list_1)
test_x2 = rnorm(50)
test_y2 = rnorm(50)
test_z2 = rnorm(50)
time_1 = rep(1, 50)
df_list_2 = list('c_X' = test_x2, 'c_Y' = test_y2, 'c_Z' = test_z2, 'time' = time_1)
df_2 = as.data.frame(df_list_2)
steps <- list(
list(args = list("visible", c(TRUE,TRUE)),
label = "Time 1 + 2",
method = "restyle",
value = "1 + 2"
),
list(args = list("visible", c(FALSE,TRUE)),
label = "Time 0",
method = "restyle",
value = "1"
),
list(args = list("visible", c(TRUE,FALSE)),
label = "Time 1",
method = "restyle",
value = "2"
)
)
p_all <- plot_ly(type = 'scatter3d', mode = 'markers') %>%
add_trace(x = df_1$c_X, y = df_1$c_Y, z = df_1$c_Z, name='Time 0') %>%
add_trace(x = df_2$c_X, y = df_2$c_Y, z = df_2$c_Z, name='Time 1') %>%
layout(title = "Visible?",
sliders = list(
list(
active = 0,
currentvalue = list(prefix = "Time: "),
pad = list(t = 60),
steps = steps)))
p_all
。 Plotly的网站上有一个例子Vagrant。粗略地实现您的问题将是:
CGMutablePath