Я пытался создать анимированный трехмерный график рассеяния в Plotly, чтобы показать, как данные датчика меняются со временем. Ploty, кажется, правильно разбивает временные рамки и помещает всю информацию датчиков в временные рамки, однако вместо обновления трассировки на каждом временном интервале он просто добавляет еще одну ко всем временным рамкам. Любые идеи о том, как построить график для каждого таймфрейма? Мой код

fig1 <- short_all_data %>%
  plot_ly(x=~one, 
          y=~two, 
          z=~three,
          size = ~temperature,
          color = ~temperature,
          frame = ~time,
          mode ='markers',
          type = 'scatter3d')
  fig1 

Фрейм данных

structure(list(time = structure(c(32761, 32761, 32761, 32761, 
32761, 32761, 32761, 32761, 32761, 32761, 32761, 32761, 32761, 
32761, 32761, 32761, 32761, 32761, 32761, 32761, 32761, 32761, 
32761, 32761, 32775, 32775, 32775, 32775, 32775, 32775, 32775, 
32775, 32775, 32775, 32775, 32775, 32775, 32775, 32775, 32775, 
32775, 32775, 32775, 32775, 32775, 32775, 32775, 32775), class = c("hms", 
"difftime"), units = "secs"), sensor_number = c("sensor_1", "sensor_2", 
"sensor_3", "sensor_4", "sensor_5", "sensor_6", "sensor_7", "sensor_8", 
"sensor_9", "sensor_10", "sensor_11", "sensor_12", "sensor_13", 
"sensor_14", "sensor_15", "sensor_16", "sensor_17", "sensor_18", 
"sensor_19", "sensor_20", "sensor_21", "sensor_22", "sensor_23", 
"sensor_24", "sensor_1", "sensor_2", "sensor_3", "sensor_4", 
"sensor_5", "sensor_6", "sensor_7", "sensor_8", "sensor_9", "sensor_10", 
"sensor_11", "sensor_12", "sensor_13", "sensor_14", "sensor_15", 
"sensor_16", "sensor_17", "sensor_18", "sensor_19", "sensor_20", 
"sensor_21", "sensor_22", "sensor_23", "sensor_24"), temperature = c(12137, 
12298, 10743, 10644, 9787, 10617, 9466, 9150, 10051, 8706, 10094, 
9541, 10326, 9983, 9494, 10044, 10126, 10436, 11848, 12141, 12216, 
11348, 0, 0, 12422, 11876, 10556, 10763, 10284, 10365, 8760, 
9684, 10068, 9649, 9940, 9913, 10316, 9527, 9939, 10378, 9920, 
9986, 11946, 12461, 11804, 11230, 50000, 0), one = c(1, 5, 1, 
5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 
1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 
5, 1, 5), two = c(1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 
5, 1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 5, 
1, 1, 5, 5, 1, 1, 5, 5, 1, 1, 5, 5), three = c(0, 0, 0, 0, 1, 
1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 0, 
0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 
5)), row.names = c(NA, -48L), groups = structure(list(sensor_number = c("sensor_1", 
"sensor_10", "sensor_11", "sensor_12", "sensor_13", "sensor_14", 
"sensor_15", "sensor_16", "sensor_17", "sensor_18", "sensor_19", 
"sensor_2", "sensor_20", "sensor_21", "sensor_22", "sensor_23", 
"sensor_24", "sensor_3", "sensor_4", "sensor_5", "sensor_6", 
"sensor_7", "sensor_8", "sensor_9"), .rows = structure(list(c(1L, 
25L), c(10L, 34L), c(11L, 35L), c(12L, 36L), c(13L, 37L), c(14L, 
38L), c(15L, 39L), c(16L, 40L), c(17L, 41L), c(18L, 42L), c(19L, 
43L), c(2L, 26L), c(20L, 44L), c(21L, 45L), c(22L, 46L), c(23L, 
47L), c(24L, 48L), c(3L, 27L), c(4L, 28L), c(5L, 29L), c(6L, 
30L), c(7L, 31L), c(8L, 32L), c(9L, 33L)), ptype = integer(0), class = c("vctrs_list_of", 
"vctrs_vctr", "list"))), row.names = c(NA, 24L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))

произведенный сюжет

Любая помощь будет оценена

1
Brian Lambert 8 Окт 2020 в 22:36

1 ответ

Лучший ответ

Я немного расширил данные вашего примера. Ваш код дает мне результат, который я ожидал:

library(plotly)

short_all_data <- data.frame(
  stringsAsFactors = FALSE,
              time = c("09:06:01","09:06:01",
                       "09:06:01","09:06:01","09:06:01","09:06:01","09:06:01",
                       "09:06:01","09:06:01","09:06:01","09:06:02","09:06:02",
                       "09:06:02","09:06:02","09:06:02","09:06:02","09:06:02",
                       "09:06:02","09:06:02","09:06:02","09:06:03",
                       "09:06:03","09:06:03","09:06:03","09:06:03","09:06:03",
                       "09:06:03","09:06:03","09:06:03","09:06:03","09:06:04",
                       "09:06:04","09:06:04","09:06:04","09:06:04","09:06:04",
                       "09:06:04","09:06:04","09:06:04","09:06:04",
                       "09:06:05","09:06:05","09:06:05","09:06:05","09:06:05",
                       "09:06:05","09:06:05","09:06:05","09:06:05","09:06:05",
                       "09:06:06","09:06:06","09:06:06","09:06:06","09:06:06",
                       "09:06:06","09:06:06","09:06:06","09:06:06",
                       "09:06:06"),
     sensor_number = c("sensor_1","sensor_2",
                       "sensor_3","sensor_4","sensor_5","sensor_6","sensor_7",
                       "sensor_8","sensor_9","sensor_10","sensor_1","sensor_2",
                       "sensor_3","sensor_4","sensor_5","sensor_6",
                       "sensor_7","sensor_8","sensor_9","sensor_10","sensor_1",
                       "sensor_2","sensor_3","sensor_4","sensor_5","sensor_6",
                       "sensor_7","sensor_8","sensor_9","sensor_10","sensor_1",
                       "sensor_2","sensor_3","sensor_4","sensor_5",
                       "sensor_6","sensor_7","sensor_8","sensor_9","sensor_10",
                       "sensor_1","sensor_2","sensor_3","sensor_4","sensor_5",
                       "sensor_6","sensor_7","sensor_8","sensor_9",
                       "sensor_10","sensor_1","sensor_2","sensor_3","sensor_4",
                       "sensor_5","sensor_6","sensor_7","sensor_8","sensor_9",
                       "sensor_10"),
       temperature = c(12137L,12298L,10743L,10644L,
                       9787L,10617L,9466L,9150L,10051L,8706L,9651L,8001L,
                       7000L,9000L,12000L,15000L,14032L,12345L,12340L,
                       12342L,12300L,11000L,11100L,11200L,11300L,11400L,
                       11500L,11600L,11700L,11800L,12137L,12298L,10743L,
                       10644L,9787L,10617L,9466L,9150L,10051L,8706L,9651L,
                       8001L,7000L,9000L,12000L,15000L,14032L,12345L,
                       12340L,12342L,12300L,11000L,11100L,11200L,11300L,11400L,
                       11500L,11600L,11700L,11800L),
               one = c(1L,5L,1L,5L,1L,5L,1L,5L,
                       1L,5L,2L,5L,1L,5L,2L,5L,1L,5L,2L,5L,1L,5L,
                       2L,5L,1L,5L,2L,5L,1L,5L,1L,5L,1L,5L,1L,5L,
                       1L,5L,1L,5L,2L,5L,1L,5L,2L,5L,1L,5L,2L,5L,1L,
                       5L,2L,5L,1L,5L,2L,5L,1L,5L),
               two = c(1L,1L,5L,5L,1L,1L,5L,5L,
                       1L,1L,1L,2L,5L,2L,1L,2L,5L,2L,1L,2L,1L,2L,
                       5L,2L,1L,2L,5L,2L,1L,2L,1L,1L,5L,5L,1L,1L,
                       5L,5L,1L,1L,1L,2L,5L,2L,1L,2L,5L,2L,1L,2L,1L,
                       2L,5L,2L,1L,2L,5L,2L,1L,2L),
             three = c(0L,0L,0L,0L,1L,1L,1L,1L,
                       2L,2L,0L,0L,2L,0L,1L,1L,2L,1L,2L,2L,2L,0L,
                       0L,0L,2L,1L,1L,1L,1L,2L,0L,0L,0L,0L,1L,1L,
                       1L,1L,2L,2L,0L,0L,2L,0L,1L,1L,2L,1L,2L,2L,2L,
                       0L,0L,0L,2L,1L,1L,1L,1L,2L)
)

fig1 <- short_all_data %>%
  plot_ly(x=~one, 
          y=~two, 
          z=~three,
          size = ~temperature,
          color = ~temperature,
          frame = ~time,
          mode ='markers',
          type = 'scatter3d')
fig1

result

0
ismirsehregal 9 Окт 2020 в 11:30