zoukankan      html  css  js  c++  java
  • R绘图系统中的坐标系

    在R语言中,对于图中的点来说,有很多种坐标系来进行定位

    举个例子:

    par(omi = c(1, 1, 1, 1), mai = c(1, 1, 1, 1), mfrow = c(1, 2))
    plot(1:5)
    box(which = "plot", col = "red", lwd = 2)
    box(which = "figure", col = "red", lwd = 2)
    plot(1:5)
    box(which = "plot", col = "blue", lwd = 2)
    box(which = "figure", col = "blue", lwd = 2)

    产生的图片如下:

    对于图中的某个具体的点来说,以蓝色子图中的点 (2, 2) 为例,有很多的坐标系统对这个点进行定位:

    1) user coordinate system : 最常用的坐标系,就是x轴和y轴构成的坐标系;x轴对应坐标为2, y轴对应坐标为2

    2)inches coordinate system : 图像左下角为(0, 0), 距离图像的下边缘和左边缘的实际距离,单位为 inches

    代码示例:

    > grconvertX(2, from = "user", to = "inches")
    [1] 4.634259
    > grconvertY(2, from = "user", to = "inches")
    [1] 2.802758

    通过gronvert 系列 函数可以看到每个点距离图像的下边缘和左边缘的实际距离

    3)device coordinate system : 绘图设备系统,单位为

    代码示例:

    > par(omi = c(1, 1, 1, 1), mai = c(1, 1, 1, 1), yaxs = "i", xaxs = "i")
    > plot(1:5)
    > grconvertX(1, from = "user", to = "dev")
    [1] 192

    我们知道点1与绘图设备的水平距离为2 inches , 2 inches = 192 pixes, 所以1 inches = 96 pixes ,  相对于incehs coordinate system, 只不过换了一个单位而已

    device coordinate system 的衡量单位为像素

    4) normalized coordinate system: 以绘图设备的左下角为坐标原点,将长和宽归一化成(0, 1)的区间,整个坐标系统中,绘图设备的左下角为(0,0), 右上角为(1,1)

    代码示例:

    > grconvertX(2, from = "user", to = "ndc")
    [1] 0.662037
    > grconvertY(2, from = "user", to = "ndc")
    [1] 0.4009908

    相当于下面的代码:

    > grconvertX(2, from = "user", to = "inches") / par("din")[1]
    [1] 0.662037
    > grconvertY(2, from = "user", to = "inches") / par("din")[2]
    [1] 0.4009908

    从上面的代码看出来,normalized coordinate system 系统中点的坐标实际为在绘图设备中的inches / 绘图设备的长或者宽

    3) normalized figure system: 和normalize device system 系统类似,只不过是这次相对于figure region 进行了归一化

    > grconvertX(2, from = "user", to = "nfc") 
    [1] 0.4537037
    > grconvertY(2, from = "user", to = "nfc")
    [1] 0.3613044

    相当于下面的代码:

    > (grconvertX(2, from = "user", to = "inches") - par("fin")[1] - par("omi")[2])/ par("fin")[1]
    [1] 0.4537037
    > (grconvertY(2, from = "user", to = "inches") - par("omi")[1])/ par("fin")[2]
    [1] 0.3613044

    从上面的代码,可以看出相对于figure region进行了归一化

    4) normalize plot system : 和normalize device system 系统类似,只不过是这次相对于plot region 进行了归一化

    代码示例:

    > grconvertX(2, from = "user", to = "npc") 
    [1] 0.2685185
    > grconvertY(2, from = "user", to = "npc")
    [1] 0.2685185

    相当于下面的代码

    > (2 - par("usr")[1]) / (par("usr")[2] - par("usr")[1])
    [1] 0.2685185
    > (2 - par("usr")[3]) / (par("usr")[4] - par("usr")[3])
    [1] 0.2685185

    从上面的代码中,就可以看出来归一化的过程

  • 相关阅读:
    [PHP]解决PHP Call to undefined function ldap_connect()
    [Nginx] Nginx配置PHP应用传递PATH_INFO变量
    [PHP]解决PHP Fatal error: Call to undefined function mcrypt_get_iv_size()
    [CentOS] centos下安装最新稳定版nginx
    [CentOS]查看centos的发行版本情况
    [MySQL]创建用户并指定某一数据库权限
    [PHP] 安装memcached扩展
    [http]301和302的区别
    [javascript] 报错SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
    [GO项目]开源免费在线客服系统-真正免费开源-GOFLY0.3.5发布-极简强大Go语言开发WEB网页客服
  • 原文地址:https://www.cnblogs.com/xudongliang/p/6927420.html
Copyright © 2011-2022 走看看