1

Hi visualization lovers,

I am trying to create a color map plot,like this one: like this one (source: https://github.com/hrbrmstr/albersusa)

BUT i want this maps to be biased so that the areas of the states to be proportional to the value I provide (in particular,I use GPD value). What i mean is that I want some states to look bigger, some smaller that they are in reality but reminding the real USA map as much as possible. No problems with the states moving or shape destroying.

Any ideas? Any ready solutions? Currently I use R and albersusa package because it is something I am familiar with. Open to change! My current code for the plot is:

           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)
Axeman
  • 32,068
  • 8
  • 81
  • 94
Maria Koroliuk
  • 297
  • 1
  • 2
  • 8
  • You could try making a cartogram? See [here](https://stackoverflow.com/questions/9319597/cartogram-choropleth-map-in-r). – Axeman Jul 18 '17 at 22:50

1 Answers1

1

Here's a very ugly first try to get you started, using the outlines from the maps package and some data manipulation from 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

# Plot both the outlines for reference and the rescaled polygons

  ggplot(df3, aes(long, lat, group = region, fill = somevalue)) + 
  geom_path() +
  geom_polygon(aes(longscale, latscale)) +
  coord_fixed() + 
  theme_void() + 
  scale_fill_viridis()

enter image description here

These outlines aren't the best, and the centroid positions they shrink toward cause the polygons to sometimes overlap the original state outline. But it's a start; you can find better shapes for US states and various centroid algorithms.

Brian
  • 7,900
  • 1
  • 27
  • 41