Adding an un-projected star for DC to Albers Equal Area projected US map

I'm creating a choropleth with all US states and territories. I want to replace the shape for Washington D.C. with a star somewhere off the coast of Maryland/Virginia. I use the following code to generate a star that I add to my tibble with state names, vertices, etc.

# star for Washington, D.C. -----------------------------------------------
star <- tribble(
  ~x, ~y, ~order, ~hole, ~piece, ~group, ~id,
  1, 0, 1, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  0.3, -0.2, 2, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  0.3, -0.95, 3, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  -0.1, -0.375, 4, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  -0.8, -0.6, 5,  FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  -0.39, 0, 6,  FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  -0.8, 0.6, 7,  FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  -0.1, 0.375, 8, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  0.3, 0.95, 9, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  0.3, 0.2, 10, FALSE, 1, "Washington, D.C.",  "Washington, D.C.", 
  1, 0, 11, FALSE, 1, "Washington, D.C.",  "Washington, D.C."
) %>%
  # rotate star by multiplying points by rotation matrix
  mutate(long = x * cos(pi / 2) + y * -sin(pi / 2),
         lat = x * sin(pi / 2) + y * cos(pi / 2)) %>%
  # scale the plots big time
  mutate(long = long,
         lat = lat) %>%
  # transpose the plot to near DC
  mutate(long = long - 75,
         lat = lat + 37) %>%
  select(-x, -y)

This actually works! Unfortunately, when I plot the map the star is projected because of coord_map(). Here's code for a reproducible example:

ggplot(star, aes(long, lat, group = group)) +
  geom_polygon() +
  scale_x_continuous(limits = c(-141, -55)) +
  scale_y_continuous(limits = c(24, 50)) +  
  coord_map(projection = "albers", lat0 = 39, lat1 = 45)

Here's the code from the full plot:

ccdf_map %>%
  ggplot() +
  geom_polygon(aes(long, lat, group = group, fill = `Job Search`), color = "#ffffff", size = 0.25) +
  geom_text(data = ccdf_labels, aes(long, lat, label = state_abbv), size = 4) +
  scale_x_continuous(limits = c(-141, -55)) +
  scale_y_continuous(limits = c(24, 50)) +
  scale_fill_manual(values = c("#0a4c6a", "#1696d2", "#a2d4ec")) +
  coord_map(projection = "albers", lat0 = 39, lat1 = 45)

ccdf_test.pdf (443.2 KB)

I want a star that is part of my tibble so fill can be mapped as an aesthetic along with all of the other states. I want the star to project as coord_equal() and the states to project as Albers Equal Area Conic Projection. My idea is to project the points in the star from Albers to equal even though the data are already stored as equal (reverse project), but I don't know how to do this with the star because it is a tibble instead of a shape file. Any ideas?

Thank you in advance for being a part of such a tremendous community!

1 Like