使用适应的状态大小创建地图

时间:2017-07-18 22:13:02

标签: r ggplot2 shapefile geo matplotlib-basemap

嗨,可视化爱好者,

我正在尝试创建一个彩色地图,如下所示:like this one (来源:https://github.com/hrbrmstr/albersusa

但是我希望这些地图有偏差,以便状态区域与我提供的值成比例(特别是,我使用GPD值)。  我的意思是,我希望有些州看起来更大,有些州看起来更小,实际上是但是尽可能地提醒真实的美国地图。 没有问题的状态移动或形状破坏。

有什么想法吗?任何现成的解决方 目前我使用R和albersusa包,因为它是我熟悉的东西。开放改变! 我目前的情节代码是:

           gmap<-
           ggplot() +
           geom_map(data = counties@data, map = cmap,
                     aes(fill =atan(y/x),alpha=x+y, map_id = name),
                     color = "gray50") +
            geom_map(data = smap, map = smap,
                     aes(x = long, y = lat, map_id = id),
                     color = "black", size = .5, fill = NA) +
            theme_map(base_size = 12) +
            theme(plot.title=element_text(size = 16, face="bold",margin=margin(b=10))) +
            theme(plot.subtitle=element_text(size = 14, margin=margin(b=-20))) +
            theme(plot.caption=element_text(size = 9, margin=margin(t=-15),hjust=0)) +
scale_fill_viridis()+guides(alpha=F,fill=F)

1 个答案:

答案 0 :(得分:1)

使用<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="page-content"> <section class="main-carousel"> <div class="carousel-cells"> <article> <div class="slide-text"> <h1>Slide One</h1> <p>A slide about sliding slides.</p> </div> </article> <article> <div class="slide-text"> <h1>Slide Two</h1> <p>A slide-sliding slider sliding slides.</p> </div> </article> <article> <div class="slide-text"> <h1>Slide Three</h1> <p>A slide-sliding slider sliding slides.</p> </div> </article> </div> <!-- Instead of using z-index place where due --> <div class="carousel-next">&gt;</div> <div class="carousel-prev">&lt;</div> </section> </div>包中的大纲和maps中的一些数据操作,这是一个非常难看的第一次尝试让您入门。

dplyr
library(maps)
library(dplyr)
library(ggplot2)

# Generate the base outlines
mapbase <- map_data("state.vbm")    

# Load the centroids
data(state.vbm.center)

# Coerce the list to a dataframe, then add in state names
# Then generate some random value (or your variable of interest, like population)
# Then rescale that value to the range 0.25 to 0.95

df <- state.vbm.center %>% as.data.frame() %>% 
  mutate(region = unique(mapbase$region),
         somevalue = rnorm(50),
         scaling = scales::rescale(somevalue, to = c(0.25, 0.95)))
df 

# Join your centers and data to the full state outlines
df2 <- df %>% 
  full_join(mapbase) 
df2

# Within each state, scale the long and lat points to be closer
#   to the centroid by the scaling factor

df3 <- df2 %>% 
  group_by(region) %>% 
  mutate(longscale = scaling*(long - x) + x,
         latscale = scaling*(lat - y) + y) 
df3

enter image description here

这些轮廓并不是最好的,它们缩小的质心位置会导致多边形有时与原始状态轮廓重叠。但这是一个开始;你可以找到美国各州更好的形状和各种质心算法。