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從上面的代碼中,就可以看出來歸一化的過程
總結
以上是生活随笔為你收集整理的R绘图系统中的坐标系的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: LInux查看CPU状态
- 下一篇: Java 两线程交替打印奇偶数(一)