【问题标题】:interactive correlation heatmap in shiny闪亮的交互式相关热图
【发布时间】:2017-05-17 14:29:43
【问题描述】:

我想在https://scip.shinyapps.io/scip_app/复制这个例子

基本上,我有一个 300 x 300 调整后的相关矩阵和一个 300 x 300 未调整的相关矩阵,并希望通过放大和缩小功能以交互方式显示它们。文本描述应显示点估计值和置信区间。

有什么模板可以快速参考吗?

【问题讨论】:

  • 你可以试试ggheatmap吗?您可以使用一些关于 SO 的问题。
  • 谷歌“热图”和“R”并查看图像。你想要的是足够接近大多数人称之为的热图。
  • 我可以轻松重现热图,但我想要的是放大功能,因为它是一个巨大的相关矩阵。你看过闪亮的例子吗?
  • 是的,有点。但是如果你想放大你可以看一下情节。 plot.ly/r/heatmaps

标签: shiny heatmap


【解决方案1】:

基于 Mike 的数据,您可以使用 d3heatmap

library(d3heatmap)
library(shiny)
n1 <- 100
n2 <- 100
nr <- 30
nc <- 30
set.seed(1)
x <- matrix(rnorm(n1), nrow=nr, ncol=nc)
y <- matrix(rnorm(n2), nrow=nr, ncol=nc)
MAT <- cor(x,y)
ui <- fluidPage(
  mainPanel(
    d3heatmapOutput("heatmap", width = "100%", height="600px")
  )
)

## server.R
server <- function(input, output) {
  output$heatmap <- renderD3heatmap({d3heatmap(MAT)})
}

shinyApp(ui = ui, server = server)

编辑:根据需要指定颜色并按原样显示数据,注意默认Colv = T,表示会将相关项组合在一起

output$heatmap <- renderD3heatmap({d3heatmap(MAT, colors = "Blues", Colv = FALSE)})

【讨论】:

  • 不错。我没有注意到他想要一个闪亮的例子......但是那个图中的数字和层次结构是什么?它们会自动带有cor() 输出吗?
  • @MikeWise,我添加了适当的颜色并删除了存在Colv = F 的排序。它默认将它们分组
  • 奇怪的是他没有投票给你。很好的答案 - 会记住该功能。其实我想我很快就能用上它了……
  • 是否有一些函数可以帮助将我们的热图链接到另一个图表或数据。就像我单击热图中的特定位置一样,它会在新位置输出该特定框的详细信息。像公司老板什么的?
【解决方案2】:

我认为 plotly 可以很好地做到这一点。这里是文档https://plot.ly/r/heatmaps/:

这是一个带有一些假数据的小模板示例(通过借用他最小的闪亮模板来回报 Porkchop 的青睐):

library(shiny)
n1 <- 100
n2 <- 100
nr <- 30
nc <- 30
set.seed(1)
x <- matrix(rnorm(n1), nrow=nr, ncol=nc)
y <- matrix(rnorm(n2), nrow=nr, ncol=nc)
cmat <- cor(x,y)
plot_ly(z = cmat, type = "heatmap")
ui <- fluidPage(
  mainPanel(
    plotlyOutput("heatmap", width = "100%", height="600px")
  )
)

## server.R
server <- function(input, output) {
  output$heatmap <- renderPlotly({plot_ly(z = cmat, type = "heatmap")})
}
shinyApp(ui,server)

这是闪亮的输出。请注意,它是完全可缩放的:

【讨论】:

  • 是否有一些函数可以帮助将我们的热图链接到另一个图表或数据。就像我单击热图中的特定位置一样,它会在新位置输出该特定框的详细信息。像公司老板什么的?
猜你喜欢
  • 2022-01-12
  • 1970-01-01
  • 2015-12-06
  • 2021-10-14
  • 2019-05-20
  • 1970-01-01
  • 1970-01-01
  • 2020-04-16
  • 1970-01-01
相关资源
最近更新 更多