R繪圖系統中的座標系

轉載自博客廬州月光,向作者表示感謝
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) 爲例,有很多的座標系統對這個點進行定位:

  1. user coordinate system : 最常用的座標系,就是x軸和y軸構成的座標系;x軸對應座標爲2, y軸對應座標爲2
  2. inches coordinate system : 圖像左下角爲(0, 0), 距離圖像的下邊緣和左邊緣的實際距離,單位爲 inches
  3. device coordinate system : 繪圖設備系統,單位爲像素
  4. 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 / 繪圖設備的長或者寬
  1. 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進行了歸一化
  1. 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
從上面的代碼中,就可以看出來歸一化的過程
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章