R绘图系统中的坐标系
程序员文章站
2022-05-20 19:45:09
...
转载自博客庐州月光,向作者表示感谢
http://www.cnblogs.com/xudongliang/p/6874659.html
在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) 为例,有很多的坐标系统对这个点进行定位:
- user coordinate system : 最常用的坐标系,就是x轴和y轴构成的坐标系;x轴对应坐标为2, y轴对应坐标为2
- inches coordinate system : 图像左下角为(0, 0), 距离图像的下边缘和左边缘的实际距离,单位为 inches
- device coordinate system : 绘图设备系统,单位为像素
- normalize device system: 以绘图设备的左下角为坐标原点,将长和宽归一化成(0, 1)的区间,整个坐标系统中,绘图设备的左下角为(0,0), 右上角为(1,1)
> grconvertX(2, from = "user", to = "inches")
[1] 4.634259
> grconvertY(2, from = "user", to = "inches")
[1] 2.802758
#通过gronvert 系列 函数可以看到每个点距离图像的下边缘和左边缘的实际距离
> 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
> 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 / 绘图设备的长或者宽
- 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进行了归一化
- 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
从上面的代码中,就可以看出来归一化的过程
上一篇: Android系统中的坐标系
下一篇: 17.ROS中的坐标系管理系统