【问题标题】:Cartogram + choropleth map in RR中的制图+等值线图
【发布时间】:2012-03-08 08:12:33
【问题描述】:

我最近一直在使用 ggplot2 来创建一堆 choropleths。我想知道是否可以使用 ggplot2 创建与此类似的地图(来自WorldMapper):

这是一个等值线,其中 shapefile 多边形被扭曲以表示相对人口计数。我相信这被称为制图。他们用一堆其他变量来做到这一点。本着Choropleth R Challenge 的精神,有谁知道如何使用 R 来做到这一点?

【问题讨论】:

  • 您可以尝试ScapeToad 获取 R 环境之外的地图。
  • 谢谢你; ScapeToad 效果很好,可以满足我的需求。但是,如果 R 中有解决方案,我会留下这个问题。
  • 我开始致力于将 d3-cartogram 与 rCharts 集成。您的数据结构是什么?
  • 刚刚偶然发现了这个。显然,R 中不存在好的选择。有两个实现制图的软件包(Rcartogramcart),但多年未更新,安装起来显然很麻烦,请参阅 stackoverflow.com/questions/31613119/…github.com/ggobi/cranvas/issues/210

标签: r ggplot2 cartogram


【解决方案1】:

CRAN 上提供的cartogram package 具有您想要的橡胶板扭曲式图表。

【讨论】:

    【解决方案2】:

    这可能有效:

    您需要预先安装 FFTW。 Rcartogram and getcartr you will need devtools.

    不确定如何在ggplot2 中执行此操作,但这里有另一种选择。

    这里我使用的是Thematic World Map的shapefile,你下载解压后会得到一个名为TM_WORLD_BORDERS-0.3的文件夹。

    对于等值线/制图,您将首先使用尺寸重塑形状,然后使用特征进行着色:

    library(rgdal)#needed for readOGR
    library(sp) #needed for spplot
    library(Rcartogram)
    library(getcartr)
    setwd("<your_directory_with_shapefile>") #to the file that has your shapefile and your information file (in this case, a csv named datR)
    #read shapefile
    #here i have a folder with a shapefile and a csv with columns as ISO (IS02 for convenience) country and value
    worldR <- readOGR(dsn = getwd(), layer= "TM_WORLD_BORDERS-0.3") # If reading a shapefile, the data source name (dsn= argument) is the folder (directory) where the shapefile is, and the layer is the name of the shapefile (without the .shp extension)
    #names(worldR) #note how here there are columns for ISO2 (which matches a column named 'iso' in datR and LAT\LON
    #[1] "FIPS"      "ISO2"      "ISO3"      "UN"        "NAME"      "AREA"      "POP2005"   "REGION"    "SUBREGION" "LON"       "LAT"
    proj4string(worldR)
    datR <- read.csv("datR.csv") #this is a file that has one column called 'score' and one column called size':
    
       head(datR)
      #  iso size     score
      #1  AE  323 0.9819077
      #2  AR  262 0.9591067
      #3  AT 7481 0.9987313
      #4  AU 5425 0.9837414
      #5  BA   31 0.9871938
      #6  BB   99 0.9715991
    
      ##Merge SpatialPolygonsDataFrame with other info
      map_dat <- merge(worldR, datR, by.x="ISO2",by.y="iso")
      #remove coordinate reference system arguments
      proj4string(map_dat) <- CRS(as.character(NA)) # from here https://github.com/chrisbrunsdon/getcartr/issues/1
      world.carto <- quick.carto(map_dat, map_dat$size, blur = 0)
      #plot(world.carto) #cartogram without anything
      #spplot size, color
      my.palette = c("#ff0000", "#ff8000", "#ffff00", "#bfff00","#00ff00") #red, orange, yellow, light green, dark green
      spplot(world.carto, 'score', col.regions = my.palette, cuts = length(my.palette)-1,main="Choropleth of score and cartogram of size")
    

    这应该会给你一个类似于这个的情节:

    我做的很匆忙,让我知道它是否有效

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多