我的算法计算对称矩阵m
。我需要做的是创建一个类似于image
的图,并使该图可以点击,这样click callback
将打印出点击的矩阵条目的位置。我怎么能用R?
m = createMatrix(data);
image(1:matrixSize,1:matrixSize,m);
答案 0 :(得分:1)
根据plotly
包尝试此解决方案
希望它可以帮到你。
# A symmetrix matrix
mtx <- cor(matrix(rnorm(1000),ncol=5))
# From wide to long format
library(reshape)
mtx.long <- melt(mtx)
# Create an image plot of the matrix
library(ggplot2)
p <- ggplot(data=mtx.long, aes(x=X1, y=X2, fill=value))+geom_raster()
# Create an interactive plot
library(plotly)
ggplotly(p)