簡體   English   中英

帶有地圖和點的繪圖矩陣

[英]Plotting matrix with map and points

我有一個矩陣A(lat,lon),其中包含值0和1。 我想繪制一張世界地圖,其中1的點圓覆蓋在帶有白色輪廓的全局地圖上。

我在網上找到了一些例子,但我一直遇到超出我范圍的問題。 我嘗試使用“圖像”,但是我錯誤地繪制了數據,點太小而看不到。 我是R的新手,並希望通過一個簡單的圖解開始學習如何在R中繪制地圖,以及添加疊加層。

任何幫助將不勝感激。 我正在使用R版本:R版本3.1.2(2014-10-31)南瓜頭盔。

我已經試過這段代碼:

 library(maps)
 library(mapdata)
 library(maptools)
 map(database = 'world',
 xlim = c(-180, 180),
 ylim = c(-90, 90),
 fill = T,
 col = 'white',
 resolution = 0,
 bg = 'white',
 mar = c(1,1,2,1))
 points(dcn18,pch = 21,cex = 2,col = 'red')
 title(xlab = 'Longitude',ylab = 'Latitude',main = '')
 axis(1, labels = T) 
 axis(2, labels = T)
 grid()
 box()

這段代碼運行良好,並生成了一張漂亮的地圖。 但是我不確定如何將這些點添加為圓,當這些點在矩陣dcn18(lat,lon)中分別為1和0時,在lat 0和lon 0處只有一個紅色圓圈。我想我需要將lon和lat數據映射到只有1個的dcn18,收集這些有效點並將它們作為數據幀傳遞給點。 但是我不知道如何在R中執行此操作。

我正在嘗試的另一種解決方案離我們更近了一些,但是由於我的數據存在NaN等問題,因此我認為“圖像”不是一個好的解決方案。

map(database = 'world',
    xlim = c(-180, 180),
    ylim = c(-90, 90),
    fill = T,
    col = 'white',
    resolution = 0,
    bg = 'white',
    mar = c(1,1,2,1))
image(seq(-180,180),seq(-90,90),dcn18.l180, xlim=c(-180,180), 
      ylim=c(-90,90), col = heat.colors(12),fill=FALSE,
      add =TRUE)

title(xlab = 'Longitude',ylab = 'Latitude',main = '')
axis(1, labels = T) 
axis(2, labels = T)
grid()
box()

K2pjP.png

坐標需要按以下順序綁定在一起:經度/緯度:

#Data Preparation: 
Lat <- c("-80", "50", "-20", "0", "20", "-50", "80" ) 
Lon <- c("-150", "-100", "-50", "0", "50", "100", "150" )

#Bind your two columns
LonLat <- cbind(Lon, Lat)

#Draw your world map here

#Draw your points on the map
points(LonLat,pch = 21,cex = 2,col = 'red')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM