在rworldmaps中绘图

时间:2017-12-20 21:51:10

标签: r

我有以下数据(纬度);

> data.frame(dms_lat[1:20])
     dms_lat.1.20.
1  40° 25' 35.8" N
2  40° 26' 28.4" N
3  40° 28' 39.8" N
4                 
5  38° 59' 15.0" N
6  40° 28' 39.9" N
7  40° 28' 39.8" N
8   40° 26' 4.3" N
9   28° 23' 2.7" N
10                
11 40° 27' 41.0" N
12 39° 38' 12.2" N
13 37° 44' 39.3" N
14 37° 21' 58.2" N
15  38° 59' 1.1" N
16  39° 38' 5.8" N
17 41° 20' 54.6" N
18 39° 30' 37.6" N
19 41° 34' 26.3" N
20  39° 38' 5.8" N

经度;

> data.frame(dms_long[1:20])
    dms_long.1.20.
1   3° 41' 19.9" W
2   3° 47' 42.2" W
3   3° 41' 11.7" W
4                 
5   3° 55' 29.6" W
6   3° 41' 11.3" W
7   3° 41' 11.7" W
8    3° 40' 8.8" W
9  16° 31' 34.3" W
10                
11   3° 40' 9.1" W
12  2° 38' 15.8" E
13  0° 57' 19.7" W
14  5° 59' 13.1" W
15  3° 55' 47.1" W
16  2° 38' 10.8" E
17   2° 7' 46.8" E
18  0° 21' 52.8" W
19   0° 39' 1.1" W
20  2° 38' 10.8" E

它有一些空白值,我不介意忽略或消除。我试图将数据绘制到地图上(西班牙)。我遵循了以下post和此post的建议并尝试清理数据。我现在拥有的是什么;

dms_lat <- gsub(" ", "", dms_lat)
dms_lat <- gsub("°", "d", dms_lat)
dms_lat <- gsub('"', " ", dms_lat)

dms_long <- gsub(" ", "", dms_long)
dms_long <- gsub("°", "d", dms_long)
dms_long <- gsub('"', " ", dms_long)

我改进了结构,但无法以正确的格式得到它我相信我应该有它。我正在尝试使用以下内容将这些数据点绘制到地图中;

library(rworldmap)
newmap <- getMap(resolution = "low")
plot(newmap, xlim = c(-20, 59), ylim = c(35, 71), asp = 1) #Map of Europe not Spain but I will find the cordinates and update the map accordingly
points(dms_long, dms_lat, col = "red", cex = 0.6)

编辑:

"36° 48' 5.3\" N", "36° 48' 51.8\" N", "36° 48' 54.7\" N", "36° 48' 56.2\" N", 
"36° 49' 21.3\" N", "36° 49' 22.4\" N", "36° 49' 54.9\" N", "36° 49' 57.1\" N", 
"36° 5' 52.1\" N", "36° 50' 17.0\" N", "36° 50' 17.2\" N", "36° 50' 17.8\" N", 
"36° 50' 22.4\" N", "36° 50' 23.1\" N", "36° 50' 26.9\" N", "36° 50' 36.0\" N", 
"36° 50' 36.5\" N", "36° 50' 38.5\" N", "36° 50' 8.2\" N", "36° 50' 8.5\" N", 
"36° 50' 9.8\" N", "36° 52' 3.7\" N", "36° 52' 57.4\" N", "36° 53' 26.5\" N", 
"36° 54' 9.3\" N", "36° 55' 31.7\" N", "36° 57' 56.1\" N", "36° 58' 28.1\" N", 
"36° 58' 40.8\" N", "36° 59' 39.2\" N", "36° 59' 44.8\" N", "36° 7' 40.2\" N", 
"36° 7' 48.9\" N", "36° 7' 50.8\" N", "36° 7' 53.5\" N", "36° 7' 56.2\" N", 
"36° 9' 38.9\" N", "36° 9' 39.2\" N", "36° 9' 46.3\" N", "36° 9' 53.9\" N", 
"37° 0' 12.8\" N", "37° 1' 13.1\" N", "37° 1' 13.2\" N", "37° 1' 37.5\" N", 
"37° 1' 41.7\" N", "37° 10' 0.9\" N", "37° 10' 10.8\" N", "37° 10' 16.5\" N", 
"37° 10' 17.2\" N", "37° 10' 18.5\" N", "37° 10' 27.2\" N", "37° 10' 33.3\" N", 
"37° 10' 37.8\" N", "37° 10' 4.0\" N", "37° 10' 47.9\" N", "37° 10' 58.6\" N", 
"37° 10' 6.5\" N", "37° 10' 8.3\" N", "37° 11' 16.9\" N", "37° 11' 17.0\" N", 
"37° 11' 19.6\" N", "37° 11' 2.6\" N", "37° 11' 21.9\" N", "37° 11' 26.2\" N", 
"37° 11' 35.8\" N", "37° 11' 54.5\" N", "37° 11' 8.2\" N", "37° 12' 32.9\" N", 
"37° 12' 5.6\" N", "37° 12' 6.2\" N", "37° 13' 12.8\" N", "37° 13' 15.5\" N", 
"37° 13' 23.4\" N", "37° 13' 28.9\" N", "37° 13' 34.1\" N", "37° 13' 34.9\" N", 
"37° 13' 37.6\" N", "37° 13' 41.5\" N", "37° 13' 43.9\" N", "37° 13' 46.4\" N", 
"37° 13' 50.3\" N", "37° 13' 6.9\" N", "37° 13' 8.8\" N", "37° 14' 2.4\" N", 
"37° 14' 29.5\" N", "37° 14' 3.6\" N", "37° 14' 36.4\" N", "37° 14' 50.0\" N", 
"37° 15' 15.0\" N", "37° 15' 15.9\" N", "37° 15' 18.8\" N", "37° 15' 20.5\" N", 
"37° 15' 21.9\" N", "37° 15' 22.5\" N", "37° 15' 25.4\" N", "37° 15' 26.0\" N", 
"37° 15' 29.0\" N", "37° 15' 30.1\" N", "37° 15' 30.7\" N", "37° 15' 33.5\" N", 
"37° 15' 33.8\" N", "37° 15' 36.4\" N", "37° 15' 39.5\" N", "37° 15' 41.8\" N", 
"37° 15' 43.6\" N", "37° 15' 44.0\" N", "37° 15' 45.9\" N", "37° 15' 48.6\" N", 
"37° 15' 48.8\" N", "37° 15' 54.4\" N", "37° 15' 56.0\" N", "37° 16' 13.3\" N", 
"37° 16' 29.0\" N", "37° 16' 31.8\" N", "37° 17' 15.8\" N", "37° 17' 35.2\" N", 
"37° 17' 35.7\" N", "37° 17' 36.3\" N", "37° 17' 52.2\" N", "37° 18' 5.1\" N", 
"37° 18' 5.3\" N", "37° 18' 54.0\" N", "37° 19' 21.3\" N", "37° 19' 55.8\" N", 
"37° 19' 58.8\" N", "37° 19' 6.5\" N", "37° 20' 11.5\" N", "37° 20' 25.4\" N", 
"37° 20' 27.4\" N", "37° 20' 33.1\" N", "37° 20' 37.2\" N", "37° 21' 0.5\" N", 
"37° 21' 2.7\" N", "37° 21' 28.4\" N", "37° 21' 29.6\" N", "37° 21' 31.4\" N", 
"37° 21' 33.8\" N", "37° 21' 36.9\" N", "37° 21' 49.8\" N", "37° 21' 58.2\" N", 
"37° 21' 6.2\" N", "37° 22' 11.1\" N", "37° 22' 19.9\" N", "37° 22' 20.4\" N", 
"37° 22' 21.1\" N", "37° 22' 23.7\" N", "37° 22' 24.6\" N", "37° 22' 25.6\" N", 
"37° 22' 26.1\" N", "37° 22' 26.7\" N", "37° 22' 27.2\" N", "37° 22' 30.2\" N", 
"37° 22' 34.8\" N", "37° 22' 41.2\" N", "37° 22' 43.4\" N", "37° 22' 45.4\" N", 
"37° 22' 48.6\" N", "37° 22' 52.6\" N", "37° 22' 55.5\" N", "37° 23' 11.8\" N", 
"37° 23' 15.3\" N", "37° 23' 15.6\" N", "37° 23' 18.8\" N", "37° 23' 18.9\" N", 
"37° 23' 2.2\" N", "37° 23' 21.2\" N", "37° 23' 21.9\" N", "37° 23' 28.2\" N", 
"37° 23' 28.3\" N", "37° 23' 33.3\" N", "37° 23' 34.6\" N", "37° 23' 35.1\" N", 
"37° 23' 35.9\" N", "37° 23' 4.1\" N", "37° 23' 51.8\" N", "37° 23' 59.9\" N", 
"37° 23' 8.3\" N", "37° 23' 9.8\" N", "37° 24' 18.8\" N", "37° 24' 2.7\" N", 
"37° 24' 39.3\" N", "37° 24' 42.9\" N", "37° 24' 45.6\" N", "37° 24' 54.9\" N", 
"37° 24' 7.7\" N", "37° 24' 8.5\" N", "37° 24' 9.1\" N", "37° 25' 10.3\" N", 
"37° 25' 25.7\" N", "37° 25' 42.4\" N", "37° 25' 43.5\" N", "37° 25' 6.3\" N", 
"37° 26' 11.1\" N", "37° 27' 45.5\" N", "37° 27' 48.9\" N", "37° 28' 20.5\" N", 
"37° 29' 18.5\" N", "37° 29' 8.2\" N", "37° 29' 8.6\" N", "37° 30' 4.8\" N", 
"37° 31' 6.0\" N", "37° 33' 1.4\" N", "37° 33' 11.2\" N", "37° 33' 20.1\" N", 
"37° 33' 43.3\" N", "37° 33' 51.6\" N", "37° 33' 52.8\" N", "37° 34' 17.5\" N", 
"37° 34' 2.2\" N", "37° 34' 24.9\" N", "37° 34' 48.1\" N", "37° 35' 17.8\" N", 
"37° 35' 3.7\" N", "37° 35' 49.2\" N", "37° 35' 51.6\" N", "37° 35' 9.7\" N", 
"37° 36' 10.0\" N", "37° 36' 15.8\" N", "37° 36' 20.0\" N", "37° 36' 38.5\" N", 
"37° 36' 5.6\" N", "37° 37' 17.3\" N", "37° 37' 19.6\" N", "37° 37' 21.7\" N", 
"37° 37' 27.8\" N", "37° 37' 29.5\" N", "37° 37' 45.6\" N", "37° 37' 6.6\" N", 
"37° 37' 7.4\" N", "37° 37' 9.8\" N", "37° 38' 16.8\" N", "37° 38' 39.8\" N", 
"37° 38' 41.7\" N", "37° 38' 55.0\" N", "37° 38' 55.2\" N", "37° 39' 11.8\" N", 
"37° 39' 18.3\" N", "37° 39' 24.0\" N", "37° 39' 26.1\" N", "37° 39' 26.3\" N", 
"37° 39' 57.3\" N", "37° 40' 11.2\" N", "37° 40' 17.2\" N", "37° 40' 2.5\" N", 
"37° 40' 28.4\" N", "37° 40' 3.7\" N", "37° 40' 31.0\" N", "37° 40' 34.3\" N", 
"37° 40' 37.5\" N", "37° 40' 37.9\" N", "37° 40' 39.9\" N", "37° 40' 53.5\" N", 
"37° 40' 8.4\" N", "37° 41' 29.5\" N", "37° 41' 47.6\" N", "37° 41' 5.5\" N", 
"37° 41' 6.8\" N", "37° 42' 31.8\" N", "37° 43' 22.5\" N", "37° 43' 33.4\" N", 
"37° 43' 9.5\" N", "37° 44' 10.8\" N", "37° 44' 37.3\" N", "37° 44' 39.3\" N", 
"37° 44' 43.9\" N", "37° 44' 48.1\" N", "37° 44' 53.3\" N", "37° 45' 44.7\" N", 
"37° 46' 12.4\" N", "37° 46' 13.9\" N", "37° 46' 23.4\" N", "37° 46' 28.2\" N", 
"37° 46' 30.8\" N", "37° 46' 56.0\" N", "37° 46' 6.9\" N", "37° 47' 51.7\" N", 
"37° 47' 52.8\" N", "37° 48' 1.1\" N", "37° 48' 11.0\" N", "37° 48' 12.0\" N", 
"37° 48' 20.1\" N", "37° 48' 3.7\" N", "37° 48' 55.8\" N", "37° 49' 10.2\" N", 
"37° 49' 21.1\" N", "37° 49' 28.4\" N", "37° 49' 4.9\" N", "37° 49' 41.4\" N", 
"37° 49' 58.9\" N", "37° 49' 7.9\" N", "37° 49' 8.5\" N", "37° 50' 36.2\" N", 
"37° 50' 46.6\" N", "37° 50' 6.1\" N", "37° 51' 0.2\" N", "37° 51' 11.9\" N", 
"37° 51' 22.1\" N", "37° 51' 32.1\" N", "37° 51' 4.8\" N", "37° 51' 5.1\" N", 
"37° 52' 23.0\" N", "37° 52' 40.0\" N", "37° 52' 54.6\" N", "37° 52' 59.3\" N", 
"37° 53' 14.3\" N", "37° 53' 19.3\" N", "37° 53' 2.3\" N", "37° 53' 20.4\" N", 
"37° 53' 20.9\" N", "37° 53' 21.0\" N", "37° 53' 28.8\" N", "37° 53' 36.2\" N", 
"37° 53' 43.2\" N", "37° 53' 5.7\" N", "37° 53' 9.4\" N", "37° 53' 9.7\" N", 
"37° 54' 22.5\" N", "37° 54' 33.9\" N", "37° 54' 35.0\" N", "37° 54' 37.4\" N", 
"37° 55' 39.6\" N", "37° 55' 44.5\" N", "37° 55' 56.7\" N", "37° 56' 14.5\" N", 
"37° 56' 16.5\" N", "37° 56' 21.9\" N", "37° 56' 33.1\" N", "37° 56' 37.4\" N", 
"37° 56' 46.9\" N", "37° 56' 9.4\" N", "37° 57' 20.9\" N", "37° 57' 21.3\" N", 
"37° 57' 30.9\" N", "37° 57' 31.5\" N", "37° 57' 31.7\" N", "37° 57' 53.5\" N", 
"37° 57' 58.2\" N", "37° 57' 58.8\" N", "37° 58' 13.6\" N", "37° 58' 14.4\" N", 
"37° 58' 14.5\" N", "37° 58' 23.7\" N", "37° 58' 26.1\" N", "37° 58' 29.4\" N", 
"37° 58' 33.7\" N", "37° 58' 34.4\" N", "37° 58' 35.5\" N", "37° 58' 36.0\" N", 
"37° 58' 37.2\" N", "37° 58' 42.0\" N", "37° 58' 43.8\" N", "37° 58' 46.1\" N", 
"37° 58' 46.2\" N", "37° 58' 46.9\" N", "37° 58' 55.3\" N", "37° 58' 57.3\" N", 
"37° 58' 58.2\" N", "37° 58' 59.3\" N", "37° 58' 59.4\" N", "37° 58' 6.1\" N", 
"37° 58' 9.8\" N", "37° 59' 0.6\" N", "37° 59' 1.7\" N", "37° 59' 11.3\" N", 
"37° 59' 12.3\" N", "37° 59' 13.3\" N", "37° 59' 17.3\" N", "37° 59' 19.6\" N", 
"37° 59' 20.1\" N", "37° 59' 21.4\" N", "37° 59' 23.6\" N", "37° 59' 26.7\" N", 
"37° 59' 27.0\" N", "37° 59' 31.7\" N", "37° 59' 33.9\" N", "37° 59' 34.2\" N", 
"37° 59' 41.3\" N", "37° 59' 41.8\" N", "37° 59' 47.8\" N", "37° 59' 49.4\" N", 
"37° 59' 5.5\" N", "37° 59' 5.7\" N", "37° 59' 56.8\" N", "37° 59' 57.3\" N", 
"37° 59' 58.4\" N", "37° 59' 6.1\" N", "37° 59' 6.8\" N", "37° 59' 8.0\" N", 
"37° 59' 8.3\" N", "37° 59' 9.5\" N", "37° 6' 43.7\" N", "37° 7' 15.3\" N", 
"37° 7' 20.8\" N", "37° 7' 28.9\" N", "37° 7' 42.6\" N", "37° 8' 25.8\" N", 
"37° 8' 30.8\" N", "37° 8' 44.6\" N", "37° 8' 59.6\" N", "37° 9' 4.4\" N", 
"37° 9' 40.2\" N", "37° 9' 43.5\" N", "37° 9' 55.6\" N", "38° 0' 1.0\" N", 
"38° 0' 15.0\" N", "38° 0' 16.7\" N", "38° 0' 21.0\" N", "38° 0' 3.5\" N", 
"38° 0' 34.5\" N", "38° 0' 47.7\" N", "38° 0' 52.9\" N", "38° 1' 16.6\" N", 
"38° 1' 17.5\" N", "38° 1' 26.1\" N", "38° 1' 28.0\" N", "38° 1' 28.2\" N", 
"38° 1' 29.6\" N", "38° 1' 34.7\" N", "38° 1' 39.7\" N", "38° 1' 47.9\" N", 
"38° 1' 59.9\" N", "38° 1' 6.5\" N", "38° 10' 46.3\" N", "38° 12' 18.8\" N", 
"38° 12' 18.9\" N", "38° 12' 22.0\" N", "38° 12' 35.0\" N", "38° 13' 39.0\" N", 
"38° 13' 57.4\" N", "38° 14' 19.9\" N", "38° 14' 23.4\" N", "38° 14' 28.0\" N", 
"38° 14' 33.6\" N", "38° 14' 36.8\" N", "38° 15' 27.8\" N", "38° 15' 28.0\" N", 
"38° 15' 35.4\" N", "38° 15' 36.4\" N", "38° 15' 45.1\" N", "38° 15' 52.2\" N", 
"38° 16' 33.2\" N", "38° 16' 4.3\" N", "38° 16' 40.6\" N", "38° 16' 5.4\" N", 
"38° 16' 58.3\" N", "38° 16' 6.5\" N", "38° 17' 42.2\" N", "38° 19' 26.7\" N", 
"38° 19' 9.7\" N", "38° 2' 12.0\" N", "38° 2' 20.4\" N", "38° 2' 28.0\" N", 
"38° 2' 44.0\" N", "38° 2' 47.6\" N", "38° 20' 36.6\" N", "38° 20' 39.8\" N", 
"38° 20' 43.8\" N", "38° 20' 46.7\" N", "38° 21' 11.5\" N", "38° 21' 28.0\" N", 
"38° 21' 36.3\" N", "38° 21' 52.0\" N", "38° 22' 38.0\" N", "38° 22' 48.8\" N", 
"38° 22' 57.7\" N", "38° 22' 59.0\" N", "38° 23' 2.4\" N", "38° 23' 2.9\" N", 
"38° 23' 5.1\" N", "38° 24' 37.9\" N", "38° 25' 35.4\" N", "38° 27' 9.0\" N", 
"38° 28' 15.9\" N", "38° 28' 17.1\" N", "38° 28' 19.6\" N", "38° 28' 21.5\" N", 
"38° 28' 27.8\" N", "38° 28' 28.1\" N", "38° 28' 38.0\" N", "38° 28' 42.0\" N", 
"38° 28' 42.4\" N", "38° 28' 45.6\" N", "38° 28' 50.1\" N", "38° 28' 60.0\" N", 
"38° 3' 11.7\" N", "38° 3' 13.0\" N", "38° 3' 13.7\" N", "38° 3' 32.0\" N", 
"38° 3' 33.2\" N", "38° 3' 35.8\" N", "38° 3' 4.8\" N", "38° 3' 43.3\" N", 
"38° 3' 44.1\" N", "38° 3' 48.8\" N", "38° 3' 5.1\" N", "38° 3' 50.2\" N", 
"38° 3' 55.9\" N", "38° 3' 9.4\" N", "38° 30' 27.9\" N", "38° 31' 16.3\" N", 
"38° 32' 16.0\" N", "38° 32' 40.4\" N", "38° 32' 8.7\" N", "38° 35' 44.6\" N", 
"38° 36' 3.4\" N", "38° 36' 37.8\" N", "38° 36' 39.9\" N", "38° 36' 40.8\" N", 
"38° 36' 49.5\" N", "38° 36' 52.5\" N", "38° 37' 1.1\" N", "38° 37' 32.5\" N", 
"38° 37' 40.0\" N", "38° 38' 13.4\" N", "38° 38' 31.7\" N", "38° 4' 25.4\" N", 
"38° 4' 31.9\" N", "38° 4' 41.5\" N", "38° 4' 44.5\" N", "38° 4' 49.0\" N", 
"38° 4' 50.3\" N", "38° 4' 51.0\" N", "38° 4' 6.6\" N", "38° 40' 15.1\" N", 
"38° 40' 54.5\" N", "38° 40' 58.1\" N", "38° 40' 58.8\" N", "38° 41' 10.6\" N", 
"38° 41' 15.4\" N", "38° 41' 18.8\" N", "38° 41' 22.8\" N", "38° 41' 25.6\" N", 
"38° 41' 28.7\" N", "38° 41' 52.1\" N", "38° 41' 52.9\" N", "38° 42' 28.9\" N", 
"38° 42' 3.2\" N", "38° 42' 54.5\" N", "38° 42' 7.7\" N", "38° 43' 10.1\" N", 
"38° 43' 3.4\" N", "38° 43' 41.0\" N", "38° 45' 26.1\" N", "38° 45' 38.6\" N", 
"38° 45' 48.8\" N", "38° 45' 53.8\" N", "38° 45' 55.7\" N", "38° 46' 26.6\" N", 
"38° 46' 4.7\" N", "38° 46' 53.6\" N", "38° 47' 16.0\" N", "38° 47' 22.4\" N", 

EDIT2:

structure(list(dms_lat.1.20. = structure(c(10L, 11L, 14L, 1L, 
6L, 15L, 14L, 12L, 2L, 1L, 13L, 8L, 4L, 3L, 5L, 9L, 16L, 7L, 
17L, 9L), .Label = c("", "28d23'2.7 N", "37d21'58.2 N", "37d44'39.3 N", 
"38d59'1.1 N", "38d59'15.0 N", "39d30'37.6 N", "39d38'12.2 N", 
"39d38'5.8 N", "40d25'35.8 N", "40d26'28.4 N", "40d26'4.3 N", 
"40d27'41.0 N", "40d28'39.8 N", "40d28'39.9 N", "41d20'54.6 N", 
"41d34'26.3 N"), class = "factor")), .Names = "dms_lat.1.20.", row.names = c(NA, 
-20L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

以下是一个例子:

dms_lat <- readLines(n=5)
1  40° 25' 35.8" N
2  40° 26' 28.4" N
3  40° 28' 39.8" N
4                 
5  38° 59' 15.0" N
dms_long <-readLines(n=5)
1   3° 41' 19.9" W
2   3° 47' 42.2" W
3   3° 41' 11.7" W
4                 
5   3° 55' 29.6" W
pts <- cbind(dms_long, dms_lat)
pts <- sub("^\\d+\\s+", "", pts)
pts[pts==""] <- NA
pts <- pts[complete.cases(pts),]
pts <- matrix(as.numeric(sp::char2dms(as.vector(pts), "°")), ncol=2)
library(rworldmap)
plot(subset(getMap(resolution = "low"), NAME=="Spain"))
points(pts[,1], pts[,2], col = "red", pch=3, cex = 0.6)

enter image description here