R的次区域地图

时间:2012-08-22 22:12:39

标签: r maps

我正在尝试在地图上绘制地理位置。我正在将ggplot2与地图库结合使用。

除了非常拥挤的地区外,一切都很好。我想放大一下这个地区,但我不能。

所以我想放大加拉帕戈斯群岛。 这是我用过的脚本:

library(ggplot2)
library(maps)

measurements <- read.csv("all_podo.count.csv", header=T)
allworld <- map_data("world")



d <- ggplot(measurements, aes(long, lat)) + 
geom_polygon(data = allworld, xlim = c(-50, 100), aes(x = long, y = lat, group = group),
colour = "grey70", fill = "grey70") +
geom_point(size = 0.7, shape = 8) + 
opts(axis.title.x = theme_blank(), 
axis.title.y = theme_blank()) +
geom_text(aes(label = name), size = 1, vjust = 0,  hjust = 0)
d

测量结果如下:

structure(list(site_num = c(59L, 54L, 44L, 42L, 38L, 37L, 43L, 
39L, 36L, 40L, 34L, 35L, 33L, 41L, 32L, 31L, 30L, 29L, 28L, 27L, 
26L, 25L, 24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 15L, 14L, 
13L, 12L, 11L, 10L, 7L, 8L, 9L, 1L, 3L, 6L, 5L, 79L, 77L, 78L, 
76L, 75L, 74L, 80L, 81L, 72L, 73L, 71L, 70L, 69L, 68L, 66L, 67L, 
65L, 63L, 64L, 62L, 60L, 61L), name = structure(c(44L, 43L, 42L, 
40L, 36L, 35L, 41L, 37L, 34L, 38L, 32L, 33L, 31L, 39L, 30L, 29L, 
28L, 27L, 26L, 25L, 24L, 23L, 22L, 21L, 20L, 19L, 18L, 17L, 16L, 
15L, 14L, 13L, 12L, 11L, 10L, 9L, 8L, 5L, 6L, 7L, 1L, 2L, 4L, 
3L, 64L, 62L, 63L, 61L, 60L, 59L, 65L, 66L, 57L, 58L, 56L, 55L, 
54L, 53L, 51L, 52L, 50L, 48L, 49L, 47L, 45L, 46L), .Label = c("GS000a", 
"GS000b", "GS000c", "GS000d", "GS001a", "GS001b", "GS001c", "GS002", 
"GS003", "GS004", "GS005", "GS006", "GS007", "GS008", "GS009", 
"GS010", "GS011", "GS012", "GS013", "GS014", "GS015", "GS016", 
"GS017", "GS018", "GS019", "GS020", "GS021", "GS022", "GS023", 
"GS025", "GS026", "GS027", "GS028", "GS029", "GS030", "GS031", 
"GS032", "GS033", "GS034", "GS035", "GS036", "GS037", "GS047", 
"GS051", "GS108a", "GS108b", "GS109", "GS110a", "GS110b", "GS111", 
"GS112a", "GS112b", "GS113", "GS114", "GS115", "GS116", "GS117a", 
"GS117b", "GS119", "GS120", "GS121", "GS122a", "GS122b", "GS123", 
"GS148", "GS149"), class = "factor"), lat = c(-15.143611, -10.131389, 
-1.9738889, 1.3891667, -0.3011111, 0.27222222, -0.020833334, 
-0.5938889, -0.2, -1.2283334, -1.2161111, -1.2169445, 1.2641667, 
-0.38305557, 5.552778, 5.64, 6.492778, 8.129167, 9.164444, 10.716389, 
18.036667, 20.5225, 24.174723, 24.488333, 32.506943, 36.003887, 
38.946945, 39.417778, 38.94, 41.09111, 41.485832, 43.63222, 45.111668, 
44.690277, 44.137222, 42.85278, 42.503056, 32.166668, 32.166668, 
32.166668, 31.175, 31.175, 31.175, 32.174835, -32.399166, -30.898333, 
-30.898333, -29.348888, -26.035, -23.21611, -6.3166666, -6.3166666, 
-4.613611, -4.613611, -4.635, -4.6625, -4.990278, -7.0075, -8.505, 
-8.505, -9.596945, -10.446111, -10.446111, -10.943611, -12.0925, 
-12.0925), long = c(-147.435, -135.44945, -95.014725, -91.81695, 
-91.651665, -91.63333, -91.19778, -91.06944, -90.83528, -90.42917, 
-90.422775, -90.319725, -90.295, -90.279724, -87.087776, -86.56528, 
-82.90389, -79.69111, -79.83611, -80.25445, -83.78472, -85.41361, 
-84.344444, -83.07, -79.263885, -75.39472, -76.41722, -75.504166, 
-74.685, -71.60222, -71.35111, -66.84722, -64.94666, -63.637222, 
-63.644444, -66.217224, -67.24, -64.5, -64.5, -64.5, -64.32433, 
-64.32433, -64.32433, -64.01017, 36.591946, 40.420277, 40.420277, 
43.215557, 50.123055, 52.30611, 39.009167, 39.009167, 55.50861, 
55.50861, 56.836113, 60.523056, 64.97667, 76.33139, 80.37556, 
80.37556, 84.1975, 88.30278, 88.30278, 92.05889, 96.88167, 96.88167
)), .Names = c("site_num", "name", "lat", "long"), class = "data.frame", row.names =     c(NA, 
-66L))

你能帮助我吗?

谢谢,

西蒙

2 个答案:

答案 0 :(得分:1)

这表明,当你达到加拉帕戈斯的水平时,包裹地图上的世界地图的分辨率并不是特别高:

if (require("maps")) { 
world <- map_data("world") 
mid_range <- function(x) mean(range(x)) 
library(plyr) 
ggplot(world, aes(long, lat)) + 
   geom_polygon( aes(group = group), fill = "green", colour = "red")+
   ylim(c(-2, 1 )) + xlim( c(-93,-88) ) }

enter image description here

似乎没有一个具有该名称的组。我想你可能想为这个项目找到一个更好的shapefile。:

  

grep(“Is”,unique(world $ region),value = TRUE)    1“以色列”
   [2]“马绍尔群岛”
   [3]“所罗门群岛”
   [4]“库克群岛”
   [5]“南桑威奇群岛”
   [6]“Sonsorol Island”
   [7]“Maug Island”
   [8]“皮特凯恩群岛”
   [9]“马恩岛”
  [10]“安达曼群岛”
  [11]“北马里亚纳群岛”   [12]“马德拉群岛”
  [13]“Sin Cowe Island”
  [14]“西沙群岛”
  [15]“福克兰群岛”
  [16]“开曼群岛”
  [17]“维尔京群岛”
  [18]“加那利群岛”
  [19]“南沙群岛”
  [20]“怀特岛”

RSeek搜索找到了几个链接。其中一个:

http://downloads.cloudmade.com/americas/south_america/ecuador/galapagos/galapagos.shapefiles.zip

“downloads.cloudmade.com上的所有文件均基于OpenStreetMap的数据,并根据Creative Commons Attribution Share-Alike 2.0许可协议的条款获得许可。如果您使用这些文件,请确保将OpenStreetMap社区归属通过链接到www.openstreetmap.org。:

答案 1 :(得分:0)

尝试在上面的代码后运行以下命令:

library(grid)
pushViewport(
  viewport( x=unit(0.1,'npc'), y=unit(0.1,'npc'), width=unit(0.2,'npc'),
    height=unit(0.2,'npc'))
)

d2 <- ggplot(measurements, aes(long, lat)) +
  geom_polygon(data = allworld, xlim = c(-50, 100), aes(x = long, y = lat, group = group), colour = "grey70", fill = "grey70") +
 geom_point(size = 0.7, shape = 8) + ylim(c(-2, 1 )) + xlim( c(-93,-88) )

print(d2, newpage=FALSE)

这应该提供添加子地图的一般概念,但是您需要调整上面的内容以获得更好的缩放效果和更好看的结果。