1

我想在 R 中生成印度地图。我有五个指标,每个州都有不同的值。我想用五种不同的颜色绘制气泡,它们的大小应该代表它们在每个状态下的强度。例如:

State A B C D E
Kerala - 39, 5, 34, 29, 11
Bihar - 6, 54, 13, 63, 81
Assam - 55, 498, 89, 15, 48,
Chandigarh - 66, 11, 44, 33, 71

我浏览了一些与我的问题相关的链接:

[1] http://www.r-bloggers.com/nrega-and-indian-maps-in-r/

[2]印度的 R 包?

但这些链接无法达到我的目的。在这个方向上的任何帮助将不胜感激。

我也试过

library(mapproj)
map(database= "world", regions  = "India", exact=T, col="grey80", fill=TRUE, projection="gilbert", orientation= c(90,0,90))

lat <- c(23.30, 28.38)

lon <- c(80, 77.12) # Lon and Lat for two cities Bhopal and Delhi

coord <- mapproject(lon, lat, proj="gilbert", orientation=c(90, 0, 90))

points(coord, pch=20, cex=1.2, col="red")

简而言之,问题是:(1)它没有给我区级的情节。甚至没有国家的边界​​。(2) 如果我只有位置名称和要绘制的相应值,如何在此图中创建数据的气泡或点?(3) 这可以在library(RgoogleMaps)or中轻松完成library(ggplot2)吗?(只是猜测,我对这些包了解不多)

4

2 回答 2

3

正如@lawyeR 所说,等值线(或专题)地图更常用于表示地图上的变量。这将要求您为每个变量生成一张地图。让我举个例子:

require("rgdal")  # needed to load shapefiles

# obtain India administrative shapefiles and unzip
download.file("http://biogeo.ucdavis.edu/data/diva/adm/IND_adm.zip", 
              destfile = "IND_adm.zip")
unzip("IND_adm.zip", overwrite = TRUE)

# load shapefiles
india <- readOGR(dsn = "shapes/", "IND_adm1")

# check they've loaded correctly with a plot
plot(india)

# all fine. Let's plot an example variable using ggplot2
require("ggplot2")
require("rgeos")  # for fortify() with SpatialPolygonsDataFrame types

india@data$test <- sample(65000:200000000, size = nrow(india@data),
                          replace = TRUE)

# breaks the shapefile down to points for compatibility with ggplot2
indiaF <- fortify(india, region = "ID_1")
indiaF <- merge(indiaF, india, by.x = "id", by.y = "ID_1")

# plots the polygon and fills them with the value of 'test'
ggplot() +
  geom_polygon(data = indiaF, aes(x = long, y = lat, group = group,
                                  fill = test)) +
  coord_equal()

最后,我注意到您在 GIS SE 上提出了同样的问题。这被认为是不好的做法,并且通常不受欢迎,因此我已将该问题标记为已关闭作为此问题的副本。作为一般经验法则,尽量不要创建重复项。

祝你好运!

于 2015-04-27T12:12:00.457 回答
1

一旦你有了印度的 shapefile,你需要创建一个choropleth。这将采用 shapefule 地图,并在反映您的数据的渐变上为印度的每个州着色。您可能想要创建一个由五个图组成的面板,每个图根据您的五个变量之一显示印度及其各州。

对于其他可以将这个答案推得更远的人dput,经过一番清理,这里是数据框的。

dput(df)
structure(list(State = c("Kerala", "Bihar", "Assam", "Chandigarh"
), A = c("39", "6", "55", "66"), B = c("5", "54", "498", "11"
), C = c("34", "13", "89", "44"), D = c("29", "63", "15", "33"
), E = c("11", "81", "48", "71")), .Names = c("State", "A", "B", 
"C", "D", "E"), row.names = c("Kerala", "Bihar", "Assam", "Chandigarh"
), class = "data.frame") 
于 2015-04-26T14:15:02.907 回答