Moving Alaska and Hawaii in geopandas for choropleths

Asked
Active3 hr before
Viewed126 times

5 Answers

movingchoroplethsgeopandashawaiialaska
90%

geopandas, pyshp and shapely must be installed for this figure factory,,This page describes a legacy "figure factory" method for creating map-like figures using self-filled scatter traces

Example_snippet/controller/utility/_moving.js/ !pip install geopandas==0.3.0 . . .
!pip install geopandas == 0.3 .0!pip install pyshp == 1.2 .10!pip install shapely == 1.6 .3
load more v
88%

For visual purposes, Alaska and Hawaii are moved the lower left corner of the contiguous US and Puerto Rico is moved closer to Florida,,Given the output data frame of covidcast

Example_snippet/controller/utility/_moving.js/ YlOrRd. . .
YlOrRd
Step 2 continued with kwargs. . .
kwargs
Step 3 continued with plot. . .
plot
load more v
72%

In a previous post we looked at how to use D3 TopoJSON files with R and make some very D3-esque maps, I mentioned that one thing missing was moving Alaska & Hawaii a bit closer to the continental United States and this post shows you how to do that

Example_snippet/controller/utility/_moving.js/ library(maptools) library(mapp. . .
library(maptools)
library(mapproj)
library(rgeos)
library(rgdal)
library(RColorBrewer)
library(gthemes)
library(ggplot2)
Step 2 continued with # https://www.census.gov/geo/m. . .
# https: //www.census.gov/geo/maps-data/data/cbf/cbf_counties.html
   # read U.S.counties moderately - simplified GeoJSON file
us < -readOGR(dsn = "data/us.geojson", layer = "OGRGeoJSON")

# convert it to Albers equal area
us_aea < -spTransform(us, CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))
us_aea @data$id < -rownames(us_aea @data)
Step 3 continued with # extract, then rotate, shrink. . .
# extract, then rotate, shrink & move alaska(and reset projection)
# need to use state IDs via # https: //www.census.gov/geo/reference/ansi_statetables.html
   alaska < -us_aea[us_aea$STATEFP == "02", ]
alaska < -elide(alaska, rotate = -50)
alaska < -elide(alaska, scale = max(apply(bbox(alaska), 1, diff)) / 2.3)
alaska < -elide(alaska, shift = c(-2100000, -2500000))
proj4string(alaska) < -proj4string(us_aea)

# extract, then rotate & shift hawaii
hawaii < -us_aea[us_aea$STATEFP == "15", ]
hawaii < -elide(hawaii, rotate = -35)
hawaii < -elide(hawaii, shift = c(5400000, -1400000))
proj4string(hawaii) < -proj4string(us_aea)

# remove old states and put new ones back in ;
note the different order
# we 're also removing puerto rico in this example but you can move it
# between texas and florida via similar methods to the ones we just used
us_aea < -us_aea[!us_aea$STATEFP % in % c("02", "15", "72"), ]
us_aea < -rbind(us_aea, alaska, hawaii)
Step 4 continued with # get some data to show...perh. . .
# get some data to show...perhaps drought data via:
   # http: //droughtmonitor.unl.edu/MapsAndData/GISData.aspx
   droughts < -read.csv("data/dm_export_county_20141111.csv")
droughts$id < -sprintf("%05d", as.numeric(as.character(droughts$FIPS)))
droughts$total < -with(droughts, (D0 + D1 + D2 + D3 + D4) / 5)

# get ready
for ggplotting it...this takes a cpl seconds
map < -fortify(us_aea, region = "GEOID")

# plot it
gg < -ggplot()
gg < -gg + geom_map(data = map, map = map,
   aes(x = long, y = lat, map_id = id, group = group),
   fill = "#ffffff", color = "#0e0e0e", size = 0.15)
gg < -gg + geom_map(data = droughts, map = map, aes(map_id = id, fill = total),
   color = "#0e0e0e", size = 0.15)
gg < -gg + scale_fill_gradientn(colours = c("#ffffff", brewer.pal(n = 9, name = "YlOrRd")),
   na.value = "#ffffff", name = "% of County")
gg < -gg + labs(title = "U.S. Areas of Drought (all levels, % county coverage)")
gg < -gg + coord_equal()
gg < -gg + theme_map()
gg < -gg + theme(legend.position = "right")
gg < -gg + theme(plot.title = element_text(size = 16))
gg
Step 5 continued with gg <- ggplot() gg <- gg + geom. . .
gg < -ggplot()
gg < -gg + geom_map(data = map, map = map,
   aes(x = long, y = lat, map_id = id, group = group),
   fill = "white", color = "white", size = 0.15)
gg < -gg + geom_map(data = us_aea @data, map = map, aes(map_id = GEOID, fill = log(ALAND)),
   color = "white", size = 0.15)
gg < -gg + scale_fill_gradientn(colours = c(brewer.pal(n = 9, name = "YlGn")),
   na.value = "#ffffff", name = "County Land\nMass Area (log)")
gg < -gg + labs(title = "U.S. County Area Choropleth (log scale)")
gg < -gg + coord_equal()
gg < -gg + theme_map()
gg < -gg + theme(legend.position = "right")
gg < -gg + theme(plot.title = element_text(size = 16))
gg
load more v
65%

I think ordinary choropleth plots at county and state levels are the first priority; metropolitan statistical areas can come later, and HRRs (healthcare referral regions) are optional,,Any priority on what types of plots/geo boundaries are most important to have implemented first?,I think something like geopandas should provide some of the choropleth functionality, and also seems to support bubble plots

Example_snippet/controller/utility/_choropleths.js/ Evalcast merge in updates. . .
Evalcast merge in updates
75%

What should I do to add subplots for Alaska and Hawaii?,I can do it in cartopy like so: Showing Alaska and Hawaii in Cartopy map,Find centralized, trusted content and collaborate around the technologies you use most,, Would it be wrong to say that the processor (and hardware) is the implementation of an interpreter for machine language?

Example_snippet/controller/utility/_choropleths.js/ low_val = 0 max_cval = len(scl. . .
low_val = 0
max_cval = len(sclass.bins) - 1
print("Population density (per square_km)")
print("Class   Value_ranges")
for ix, val in enumerate(sclass.bins):
   #print(low_val, "< x <=", val)
print("{ix:}    {low_val:.2f} < density <= {val:.2f}".format(ix = ix, low_val = low_val, val = val))
#print(my_colormap(ix / max_cval))
low_val = val
load more v