意外地转换来自R“图像”的翻转输出。功能 [英] Unexpectedly transposed flipped output from R "image" function

查看:141
本文介绍了意外地转换来自R“图像”的翻转输出。功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个矩阵:

m<-matrix(1:5,4,5)
m
     [,1] [,2] [,3] [,4] [,5]
[1,]    1    5    4    3    2
[2,]    2    1    5    4    3
[3,]    3    2    1    5    4
[4,]    4    3    2    1    5

现在,我什么时候

image(m)

我得到意外的输出。所以我需要这样做:

I get unexpected output. And so I need to do:

image(t(m)[,4:1])

以正确的方式获得它。有什么意义?

to get it the "right" way. What is the point?

推荐答案

其他人已经指出你所看到的与文档一致,这里有几个关于它为什么这样做的想法。

Others have pointed out that what you are seeing is consistent with the documentation, here are a couple of thoughts of the why it does it that way.

图像功能最初并不是用来绘制图像/图形,而是用图形表示表格信息,因此是事物的顺序旨在与其他图形理想保持一致,而不是确保剪贴画看起来正确。这意味着图像的旋转和镜像不会使其错误,它只是一个不同的视图,并且选择了遵循绘图规则的视图。

The image function was not originally designed to plot images/graphics, but to represent tabular information graphically, therefore the ordering of things was intended to be consistent with other graphing ideals rather than making sure that clipart looked correct. This means that rotations and mirroring of the image does not make it "wrong", it is just a different view, and the view that followed the plotting rules was chosen.

它还试图与其他图形功能及其所基于的理念保持一致。对于散点图,我们使用 plot(x,y),其中 x 是水平轴,但是当我们做 table(x,y) x 变量形成结果表的行。这两个事实都与通常的做法一致(解释变量通常是表中的行变量,因为数字更容易垂直比较)。因此,图像函数使用矩阵的行(如果来自表函数,则为x变量)作为横轴上的预测变量/解释变量。通常情况下,图中的值从左到右和从下到上增加(但在表格中,从上到下增加更为常见)。

It also tried to be consistent with other graphing functions and the philosophy that they were based on. For a scatter plot we use plot(x,y) with x being the horizontal axis, but when we do table(x,y) the x variable forms the rows of the resulting table. Both of these facts are consistent with common practice (the explanatory variable is generally the row variable in a table since numbers are easier to compare vertically). So the image function uses the rows of the matrix (the x variable if it came from the table function) as the predictor/explanatory variable on the horizontal axis. It is also customary for values in plots to increase going left to right and bottom to top (but in tables it is more common to increase going top to bottom).

这篇关于意外地转换来自R“图像”的翻转输出。功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆