Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two AK counties not mapped correctly!? #72

Closed
USMortality opened this issue Nov 23, 2023 · 5 comments · Fixed by #76
Closed

Two AK counties not mapped correctly!? #72

USMortality opened this issue Nov 23, 2023 · 5 comments · Fixed by #76
Assignees
Labels
bug A bug or issue that should be resolved
Milestone

Comments

@USMortality
Copy link

USMortality commented Nov 23, 2023

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

@USMortality USMortality added the bug A bug or issue that should be resolved label Nov 23, 2023
@pdil
Copy link
Owner

pdil commented Nov 23, 2023

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
Copy link
Author

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

@USMortality USMortality reopened this Nov 23, 2023
@pdil pdil self-assigned this Nov 24, 2023
@pdil
Copy link
Owner

pdil commented Nov 24, 2023

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

@pdil
Copy link
Owner

pdil commented Dec 11, 2023

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 added a commit to pdil/usmapdata that referenced this issue Dec 11, 2023
* Added `fips_data` function to load FIPS data from included csv files
* Provides cleaner way to load FIPS data in `usmap` package without
loading `extdata` file

See
[pdil/usmap#58](pdil/usmap#72 (comment))
@pdil
Copy link
Owner

pdil commented Dec 11, 2023

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

See pdil/usmapdata#4

@pdil pdil added this to the v0.7.0 milestone Dec 11, 2023
@pdil pdil closed this as completed in #76 Dec 11, 2023
pdil added a commit that referenced this issue Dec 11, 2023
* Added support for `usmapdata 0.1.2` which includes `fips_data()`
function for retrieving state and county FIPS codes.
  * Deleted state and county FIPS files contained in `usmap`.
* Files were outdated and now come from single source of truth in
`usmapdata`.

resolves #72
pdil added a commit to pdil/usmapdata that referenced this issue Dec 27, 2023
* Added `fips_data` function to load FIPS data from included csv files
* Provides cleaner way to load FIPS data in `usmap` package without
loading `extdata` file

See
[pdil/usmap#58](pdil/usmap#72 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug or issue that should be resolved
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants