Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:30:06+00:00 2026-06-15T16:30:06+00:00

I am trying to create a thematic map showing all 50 US states, but

  • 0

I am trying to create a thematic map showing all 50 US states, but I am having trouble relocating Alaska and Hawaii in a reliable way. I have a couple of ideas but none of them work well. I will demonstrate them now.

First we need to import the data; using the data in the maps package is not enough because it does not include Hawaii and Alaska.

setwd(tempdir())
download.file("https://dl.dropbox.com/s/wl0z5rpygtowqbf/states_21basic.zip?dl=1", 
              "usmapdata.zip", 
              method = "curl")
# This is a mirror of http://www.arcgis.com/home/item.html?
# id=f7f805eb65eb4ab787a0a3e1116ca7e5
unzip("usmapdata.zip")

require(rgdal)
all_states <- readOGR("states_21basic/", "states")

require(ggplot2); require(maptools); require(rgeos); require(mapproj);
all_states <- fortify(all_states, region = "STATE_NAME")

Now we define some plot aesthetics:

p <- ggplot() + geom_polygon( 
  aes(x=long, y=lat, group = group, fill = as.numeric(as.factor(id))), 
  colour="white", size = 0.25
) + coord_map(projection="azequalarea") + 
scale_fill_gradient(limits = c(1,50))

Now we remove all background etc so they don’t clash when we overlap the non-contiguous states:

p <-   p + theme(axis.line=element_blank(),
            axis.text.x=element_blank(),
            axis.text.y=element_blank(),
            axis.ticks=element_blank(),
            axis.title.x=element_blank(),
            axis.title.y=element_blank(),
            panel.background=element_blank(),
            panel.border=element_blank(),
            panel.grid.major=element_blank(),
            panel.grid.minor=element_blank(),
            plot.background=element_blank())

Using viewports

The first idea I had was to use viewports:

AK <- p %+% subset(all_states, id == "Alaska") + theme(legend.position = "none")
HI <- p %+% subset(all_states, id == "Hawaii") + theme(legend.position = "none")
contiguous <- p %+% subset(all_states, id != "Alaska" & id != "Hawaii")

grid.newpage()
vp <- viewport(width = 1, height = 1)
print(contiguous, vp = vp)
subvp1 <- viewport(width = 0.25, height = 0.25, x = 0.18, y = 0.33)
print(AK, vp = subvp1)
subvp2 <- viewport(width = 0.12, height = 0.12, x = 0.32, y = 0.27)
print(HI, vp = subvp2)

enter image description here

This looks nice but it is not satisfactory because it is very sensitive to slight changes in the figure, for example resizing or changes in the size and shape of the legend.

Manually moving Alaska and Hawaii

all_states_AKHImoved <- within(all_states, {
  lat[id == "Alaska"] <- lat[id == "Alaska"] - 45
  long[id == "Alaska"] <- long[id == "Alaska"] + 40
  lat[id == "Hawaii"] <- lat[id == "Hawaii"] + 0
  long[id == "Hawaii"] <- long[id == "Hawaii"] + 70
})
p %+% all_states_AKHImoved

enter image description here

This is not satisfactory because Alaska is usually not to scale on most US maps so it looks very big. Also relocating Alaska and Hawaii changes the distortion introduced by the map projection.

Question

Does anyone have any better approaches?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:30:07+00:00Added an answer on June 15, 2026 at 4:30 pm

    Here’s how to do it by projecting and transforming. You will need:

    require(maptools)
    require(rgdal)
    
    fixup <- function(usa,alaskaFix,hawaiiFix){
    
      alaska=usa[usa$STATE_NAME=="Alaska",]
      alaska = fix1(alaska,alaskaFix)
      proj4string(alaska) <- proj4string(usa)
    
      hawaii = usa[usa$STATE_NAME=="Hawaii",]
      hawaii = fix1(hawaii,hawaiiFix)
      proj4string(hawaii) <- proj4string(usa)
    
      usa = usa[! usa$STATE_NAME %in% c("Alaska","Hawaii"),]
      usa = rbind(usa,alaska,hawaii)
    
      return(usa)
    
    }
    
    fix1 <- function(object,params){
      r=params[1];scale=params[2];shift=params[3:4]
      object = elide(object,rotate=r)
      size = max(apply(bbox(object),1,diff))/scale
      object = elide(object,scale=size)
      object = elide(object,shift=shift)
      object
    }
    

    Then read in your shapefile. Use rgdal:

    us = readOGR(dsn = "states_21basic",layer="states")
    

    Now transform to equal-area, and run the fixup function:

    usAEA = spTransform(us,CRS("+init=epsg:2163"))
    usfix = fixup(usAEA,c(-35,1.5,-2800000,-2600000),c(-35,1,6800000,-1600000))
    plot(usfix)
    

    The parameters are rotations, scaling, x and y shift for Alaska and Hawaii respectively, and were obtained by trial and error. Tweak them carefully. Even changing Hawaii’s scale parameter to 0.99999 sent it off the planet because of the large numbers involved.

    If you want to turn this back to lat-long:

    usfixLL = spTransform(usfix,CRS("+init=epsg:4326"))
    plot(usfixLL)
    

    But I’m not sure if you need to use the transformations in ggplot since we’ve done that with spTransform.

    You can now jump through the ggplot2 fortify business. I’m not sure if it matters for you but note that the order of the states is different in the usfix version – Alaska and Hawaii are now the last two states.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to create a black line in my view to separate text blocks but
Trying to create a new Dedicated Cache Role in Windows Azure but get the
I'm trying create a RCP Application with Eclipse, but I can't get past the
I'm trying create a new file with a Java Applet, but I don't know
I am new to asp.net & trying create a object, but there is a
I'm trying create a connection using Spring 3.2.0 but I get NullPointerException of: ApplicationContext
I am trying create alert dailog using glade,but its not working .am i doing
I am trying create a node in ejabber using XMPP and BOSH Manager. But
I am trying create a new css for shaping my detailsview. But i couldn't
I'm trying create a simple audio stream server like a concept proof, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.