R图像()绘制矩阵旋转? [英] R image() plots matrix rotated?
本文介绍了R图像()绘制矩阵旋转?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在阅读
如何使布局相同作为印刷矩阵?这不仅仅是让转置翻转x和y,因为它会以倒置图像结束。
解决方案
你可以反转矩阵,然后转置。
mat1< - apply(mat1,2,rev)
图像(1:3,1:3,t(mat1))
因为它绘制而令人困惑从下到上按行排列,但R按列向下索引矩阵。因此,第一行中从左到右的像素对应于矩阵中的第一列,自上而下。
I've been reading the docs for R image()
but I don't get it. Why does this matrix:
> mat1
[,1] [,2] [,3]
[1,] 1 0 1
[2,] 0 1 0
[3,] 0 0 0
Plotted like this:
> image(c(1:3), c(1:3), mat1)
yield this:
And how can I make the layout the same as the printed matrix? It's not a matter of just taking the transpose to flip x and y, as that ends up with an 'upside down' image.
解决方案
You could reverse the matrix, then transpose.
mat1 <- apply(mat1, 2, rev)
image(1:3, 1:3, t(mat1))
It's confusing because it draws by row from bottom up, but R indexes matrices by column, top down. So, the pixels in the first row, from left to right, correspond to the first column in the matrix, top down.
这篇关于R图像()绘制矩阵旋转?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文