有清楚地为各种各样的空间分析的数中的R包。可通过看到在 CRAN任务视图:空间数据分析。这些包是纷繁多样,但我想要做的是一些简单的专题地图。我有县和状态数据FIPS码和我有县和州边界的ESRI形状的文件和其允许与数据结合伴随的FIPS码。形状文件可以在需要时很容易地转换为其它格式。

那么,什么是创造有R专题地图最直接的方法是什么?

此地图看起来就像是与ESRI弧产品上创建的,但是这是我想,其中R做的事情的类型:

替代文字http://www.infousagov.com/images/choro.jpg 从这里复制。

有帮助吗?

解决方案

下面的代码曾我很好。自它一点点,你就完成了。 “替代文字” 结果 <子>(来源: eduardoleoni.com

library(maptools)
substitute your shapefiles here
state.map <- readShapeSpatial("BRASIL.shp")
counties.map <- readShapeSpatial("55mu2500gsd.shp")
## this is the variable we will be plotting
counties.map@data$noise <- rnorm(nrow(counties.map@data))

热图功能

plot.heat <- function(counties.map,state.map,z,title=NULL,breaks=NULL,reverse=FALSE,cex.legend=1,bw=.2,col.vec=NULL,plot.legend=TRUE) {
  ##Break down the value variable
  if (is.null(breaks)) {
    breaks=
      seq(
          floor(min(counties.map@data[,z],na.rm=TRUE)*10)/10
          ,
          ceiling(max(counties.map@data[,z],na.rm=TRUE)*10)/10
          ,.1)
  }
  counties.map@data$zCat <- cut(counties.map@data[,z],breaks,include.lowest=TRUE)
  cutpoints <- levels(counties.map@data$zCat)
  if (is.null(col.vec)) col.vec <- heat.colors(length(levels(counties.map@data$zCat)))
  if (reverse) {
    cutpointsColors <- rev(col.vec)
  } else {
    cutpointsColors <- col.vec
  }
  levels(counties.map@data$zCat) <- cutpointsColors
  plot(counties.map,border=gray(.8), lwd=bw,axes = FALSE, las = 1,col=as.character(counties.map@data$zCat))
  if (!is.null(state.map)) {
    plot(state.map,add=TRUE,lwd=1)
  }
  ##with(counties.map.c,text(x,y,name,cex=0.75))
  if (plot.legend) legend("bottomleft", cutpoints, fill = cutpointsColors,bty="n",title=title,cex=cex.legend)
  ##title("Cartogram")
}

情节它

plot.heat(counties.map,state.map,z="noise",breaks=c(-Inf,-2,-1,0,1,2,Inf))

其他提示

想我会在这里增加一些新的信息,因为那里已经出现了自张贴这个话题的一些活动。下面是对革命博客两大环节,以“地区分布图 - [R挑战”:

地区分布图 - [R挑战

等值线挑战结果

希望这些都是人查看此问题是有用的。

所有最好的,

检查出包

library(sp)
library(rgdal)

其是很好的对地理数据,以及

library(RColorBrewer)  

为着色是有用的。 此地图由与上述包和该代码:

VegMap <- readOGR(".", "VegMapFile")
Veg9<-brewer.pal(9,'Set2')
spplot(VegMap, "Veg", col.regions=Veg9,
 +at=c(0.5,1.5,2.5,3.5,4.5,5.5,6.5,7.5,8.5,9.5),
 +main='Vegetation map')

"VegMapFile"是shape文件和"Veg"是显示的变量。大概可以做一点点工作做得更好。我不`吨似乎允许上传图像,这里是一个链接到图像:

看一看的PBSmapping包(见borh晕影/手动和演示)和 的O'Reilly的数据混搭中的R 文章(不幸的是这不是免费的,但它是值得$ 4.99下载,根据转博客)。

它仅仅是三行!

library(maps);
colors = floor(runif(63)*657);
map("state", col = colors, fill = T, resolution = 0)

完成! 只是第二线路改变到63个元件的任何矢量(0和657之间的每个元件,其是颜色成员())

现在,如果你想获得看上你可以这样写:

library(maps);
library(mapproj);
colors = floor(runif(63)*657);
map("state", col = colors, fill = T, projection = "polyconic", resolution = 0);

在63个元素代表了63个区的名字,你可以通过运行得到:

map("state")$names;

R图形库具有非常类似地图其应使一个很好的起点。该代码是在这里:www.ai.rug.nl/~hedderik/R/US2004。你需要添加一个传奇与传奇()函数。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top