我需要通过 plotly 制作一个热图来显示更多信息
I need a make a heatmap by plotly that shows more information
我希望能够制作一个 R plotly 热图,除了显示有关 z 的信息外,我还会有更多信息,这将是文本信息。
我的意思是:我有这个数据集dataset:
library(plotly)
m <- matrix(c(NA, 1,3, 2, NA, 4, 3, 0, NA), nrow = 3, ncol = 3)
fig <- plot_ly(
x = c("Epilepsy", "PTSD", "Depression"), y = c("Dizziness", "Slowed Thinking/ Decision-making
", "Hearing/Noise Sensitivity
"),
z = m, type = "heatmap"
)
这给了我这个输出:
但是,当我点击每个部分时我需要更多的东西我也有这个变量:
p <- matrix(c(NA, "XX","YY", "TT", NA, "ST", "PO", "IU", NA), nrow = 3, ncol = 3)
如您所见,这不是数字,它只是提供有关关联的更多信息。
您可以将矩阵 p
添加到 text
属性,即
fig <- plot_ly(
x = x,
y = y,
z = m,
type = "heatmap",
text = p
)
完整代码
library(plotly)
m <- matrix(c(NA, 1,3, 2, NA, 4, 3, 0, NA), nrow = 3, ncol = 3)
p <- matrix(c(NA, "XX","YY", "TT", NA, "ST", "PO", "IU", NA), nrow = 3, ncol = 3)
fig <- plot_ly(
x = x,
y = y,
z = m,
type = "heatmap",
text = p
)
fig
我希望能够制作一个 R plotly 热图,除了显示有关 z 的信息外,我还会有更多信息,这将是文本信息。
我的意思是:我有这个数据集dataset:
library(plotly)
m <- matrix(c(NA, 1,3, 2, NA, 4, 3, 0, NA), nrow = 3, ncol = 3)
fig <- plot_ly(
x = c("Epilepsy", "PTSD", "Depression"), y = c("Dizziness", "Slowed Thinking/ Decision-making
", "Hearing/Noise Sensitivity
"),
z = m, type = "heatmap"
)
这给了我这个输出:
但是,当我点击每个部分时我需要更多的东西我也有这个变量:
p <- matrix(c(NA, "XX","YY", "TT", NA, "ST", "PO", "IU", NA), nrow = 3, ncol = 3)
如您所见,这不是数字,它只是提供有关关联的更多信息。
您可以将矩阵 p
添加到 text
属性,即
fig <- plot_ly(
x = x,
y = y,
z = m,
type = "heatmap",
text = p
)
完整代码
library(plotly)
m <- matrix(c(NA, 1,3, 2, NA, 4, 3, 0, NA), nrow = 3, ncol = 3)
p <- matrix(c(NA, "XX","YY", "TT", NA, "ST", "PO", "IU", NA), nrow = 3, ncol = 3)
fig <- plot_ly(
x = x,
y = y,
z = m,
type = "heatmap",
text = p
)
fig