Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用R中的滑块绘制多个数据帧的热图_R_Ggplot2_Plotly_Heatmap_Ggplotly - Fatal编程技术网

使用R中的滑块绘制多个数据帧的热图

使用R中的滑块绘制多个数据帧的热图,r,ggplot2,plotly,heatmap,ggplotly,R,Ggplot2,Plotly,Heatmap,Ggplotly,我有多个data.frames,每一个都代表不同时间点的个体成对交互 下面是我的data.frames的外观示例 df1 <- matrix(data = rexp(9, rate = 10), nrow = 3, ncol = 3) df2 <- matrix(data = rexp(16, rate = 10), nrow = 4, ncol = 4) df3 <- matrix(data = rexp(4, rate = 10), nrow = 2, ncol = 2)

我有多个data.frames,每一个都代表不同时间点的个体成对交互

下面是我的data.frames的外观示例

df1 <- matrix(data = rexp(9, rate = 10), nrow = 3, ncol = 3)
df2 <- matrix(data = rexp(16, rate = 10), nrow = 4, ncol = 4)
df3 <- matrix(data = rexp(4, rate = 10), nrow = 2, ncol = 2)

df1遵循
正弦波滑块
示例可以这样实现。我的方法的第一步涉及将矩阵转换为具有x、y、z列的数据帧。其次,我们绘制热图而不是线

df1 <- matrix(data = rexp(9, rate = 10), nrow = 3, ncol = 3)
df2 <- matrix(data = rexp(16, rate = 10), nrow = 4, ncol = 4)
df3 <- matrix(data = rexp(4, rate = 10), nrow = 2, ncol = 2)

library(tibble)
library(tidyr)
library(plotly)

# Make dataframes
d <- lapply(list(df1, df2, df3), function(d) {
            d %>%
              as_tibble(.colnames = seq(ncol(.))) %>% 
              rowid_to_column("x") %>% 
              pivot_longer(-x, names_to = "y", values_to = "z") %>% 
              mutate(y = stringr::str_extract(y, "\\d"),
                     y = as.numeric(y))
    })

aval <- list()
for(step in seq_along(d)){
  aval[[step]] <-list(visible = FALSE,
                      name = paste0('v = ', step),
                      x = d[[step]]$x,
                      y = d[[step]]$y,
                      z = d[[step]]$z)
}
aval[1][[1]]$visible = TRUE

steps <- list()
fig <- plot_ly()

for (i in seq_along(aval)) {
  fig <- add_trace(fig, x = aval[i][[1]]$x, y = aval[i][[1]]$y, z = aval[i][[1]]$z, visible = aval[i][[1]]$visible, 
                   name = aval[i][[1]]$name, type = "heatmap")
  fig
  step <- list(args = list('visible', rep(FALSE, length(aval))), method = 'restyle')
  
  step$args[[2]][i] = TRUE  
  steps[[i]] = step
}

fig <- fig %>%
  layout(sliders = list(list(active = 0,
                             currentvalue = list(prefix = "Heatmap: "),
                             steps = steps)))
fig
df1%
突变(y=stringr::str_extract(y,“\\d”),
y=作为数字(y))
})
阿瓦尔