pdil / usmap

🗺 Create US maps including Alaska and Hawaii in R
https://usmap.dev/
GNU General Public License v3.0
74 stars 16 forks source link

Two AK counties not mapped correctly!? #72

Closed USMortality closed 10 months ago

USMortality commented 11 months ago

Describe the bug Using the built-in county list, and the provided sample population file, I can see that two Alaska counties are not mapped correctly.

Any idea?

To Reproduce

df = read_csv(system.file("extdata", "county_fips.csv", package = "usmap"))
df$pop_2015 = 1000
usmap::plot_usmap(
    data = df,
    "counties",
    values = "pop_2015",
    color = NA
) + scale_fill_viridis_c(
    option = "D",
    na.value = "#bbbbbb",
    name = "population"
)

Same happens with: countypop <- readxl::read_excel("https://raw.githubusercontent.com/pdil/usmap/master/data-raw/countypop.xlsx")

plot-1

pdil commented 11 months ago

In 2019 the Valdez-Cordova Census Area in Alaska split into two separate areas (Chugach Census Area and Copper River Census Area) which is what you're seeing there as gray in the map.

The population dataset included in the package is from 2015 which is why it doesn't account for those. The map itself should be correct since the shape files were updated in 2020 but I can double-check to make sure.

Thanks for bringing this to my attention though, it's probably worth updating the included sample data 😅

USMortality commented 11 months ago

Yes, so the library appears to handle the latest census counties then correctly, thx.

Here's the updated sample code, it seems that county_fips.csv maybe should be updated as well.

df <- read_csv(system.file("extdata", "county_fips.csv", package = "usmap")) |>
    select(fips)
df$pop <- 1000

# Manually add the two new AK counties
df2 <- df |>
    add_row(tibble(
        fips = "02063",
        pop = 1000
    )) |>
    add_row(tibble(
        fips = "02066",
        pop = 1000
    ))

usmap::plot_usmap(
    data = df2,
    "counties",
    values = "pop",
    color = NA
) + scale_fill_viridis_c(
    option = "D",
    na.value = "#bbbbbb",
    name = "population"
)

plot

pdil commented 11 months ago

Good point, looks like they are missing from county_fips.csv. I'll be sure to add it in for the next release.

pdil commented 11 months ago

After some investigation it appears I already added these counties to usmapdata but the usmap functions fips and fips_info are still referring to the older files stored in usmap. I'm currently in the process of removing these and referencing the data in usmapdata directly so there's a single source for the FIPS data.

pdil commented 11 months ago

usmapdata is currently being released to CRAN. When it is uploaded I can update usmap with the changes.

See https://github.com/pdil/usmapdata/pull/4