R点击矩阵图的位置

时间:2017-07-08 20:49:38

标签: r matrix

我的算法计算对称矩阵m。我需要做的是创建一个类似于image的图,并使该图可以点击,这样click callback将打印出点击的矩阵条目的位置。我怎么能用R?

这样做
m = createMatrix(data);  
image(1:matrixSize,1:matrixSize,m);

1 个答案:

答案 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)

enter image description here