pdil / usmap Goto Github PK
View Code? Open in Web Editor NEW๐บ Create US maps including Alaska and Hawaii in R
Home Page: https://usmap.dev/
License: GNU General Public License v3.0
๐บ Create US maps including Alaska and Hawaii in R
Home Page: https://usmap.dev/
License: GNU General Public License v3.0
Love the package -- great for quick/easy mapping.
Would it be straightforward to add support for Public Use Microdata Area (PUMA) geography?
That would allow for mapping of PUMA-level values derived from American Community Survey microdata files.
Is your feature request related to a problem? Please describe.
Users have requested the ability to define visual properties of the defined US Census Bureau regions such as borders and fill colors.
Describe the solution you'd like
A new shape file would probably have to be constructed where each state within the region is merged into a single entity. New parameters would have to be added to plot_usmap
to define which regions' visual properties should be modified and how.
Describe alternatives you've considered
None, this idea will require some refinement and planning.
Additional context
Related StackOverflow questions:
The R CMD check and test coverage workflows cause the following deprecation warning:
The
set-env
command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
More info: https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/
Please correct me if I am wrong here, but the only spatial features I see in the maps are to obtain the CRS, and transform the object to a data frame (but not an SPDF). I see there is an option to snap other data frames having the same CRS to the usmap (gg).
Is there a simple way to back-transform the gg object to an SPDF or other spatial format outside gg universe?
Describe the bug
Tests fail on certain r-devel environments due to changes in R discussed here: https://stat.ethz.ch/pipermail/r-devel/2020-December/080172.html
To Reproduce
See logs here: https://cran.r-project.org/web/checks/check_results_usmap.html
Expected behavior
All tests should run properly and successfully on all environments.
Environments:
usmap 0.5.1
r-devel-linux-x86_64-debian-clang
r-devel-linux-x86_64-debian-gcc
r-devel-linux-x86_64-fedora-clang
r-devel-linux-x86_64-fedora-gcc
r-devel-windows-ix86+x86_64
Additional context
Possible solution here: Ryo-N7/tvthemes#15
Must be resolved by January 8, 2021 to prevent removal from CRAN.
No shapes for this county are contained in the us_counties.csv file.
Currently, plotting and merging with the map data requires a data frame containing a fips
column. The data should be able to be plotted with a column of state abbreviations or names as well.
This can be easily achieved by converting to FIPS codes with the fips
function internally if abbreviations/names are detected.
Sent with GitHawk
The following states may cause issues when plotting with data because the leading zero may be omitted if the input data is numeric rather than a character (e.g. "01"
becomes 1
and "01001"
becomes 1001
). This affects any counties within the following states as well.
Abbr FIPS Name
==== ==== ====
AK 02 ALASKA
AL 01 ALABAMA
AR 05 ARKANSAS
AZ 04 ARIZONA
CA 06 CALIFORNIA
CO 08 COLORADO
CT 09 CONNECTICUT
The solution will be to cast the input fips
column to characters and make sure they are padded correctly ("00"
for states and "00000"
for counties).
plot_usmap is confused when a column is named "values"
str(myDF)
$ fips : Factor w/ 30 levels ...
$ values : int ...
plot_usmap(data = myDF)
Error in [.data.frame(map_df, , values) : undefined columns selected
plot_usmap(data = myDF, values = "values" )
Error in [.data.frame(map_df, , values) : undefined columns selected
str(myDF)
$ fips : Factor w/ 30 levels ...
$ population : int ...
plot_usmap(data = myDF, values = "population" )
I get the error listed in the title of this issue when running a simple program:
library("usmap")
library("ggplot2")
fipsCodes <- c("54001","54003")
values <- c(10,20)
mapData <- data.frame (fipsCodes,values,stringsAsFactors=FALSE)
names(mapData) <- c("fips","value")
meanValue <- mean(values)
usmap::plot_usmap(data = mapData, values="value", lines="red",
regions="counties",
include = c("WV"),
scale_fill_continuous(low="#559999",mid="grey90",high="#886508",midpoint=meanValue),
theme(legend.position = "right"))
Error in if (labels) { : argument is not interpretable as logical
If I remove the line containing the parameter "scale_fill_continuous(...", it works fine.
The county map should be able to display only counties in certain states using the include
parameter.
For example,
plot_usmap("counties", include = c("NJ", "PA", "NY"))
This can be fixed at this location in usmap.R:
if (length(include) > 0) {
if (regions_ %in% c("counties", "county")) {
df <- df[df$fips %in% include, ]
} else {
df <- df[df$full %in% include | df$abbr %in% include | df$fips %in% include, ]
}
}
The body of the if
statement should be changed to:
if (length(include) > 0) {
df <- df[df$full %in% include | df$abbr %in% include | df$fips %in% include, ]
}
This should work because both the county and state map files have columns fips
, full
, and abbr
.
Updating this function also has the added side-effect of allowing users to specify any combination of states and counties to include using either FIPS code, state abbreviation, state name, or a mixture of the three.
Describe the bug
This used to work in version 0.2.1, now an error is returned.
To Reproduce
Steps to reproduce the behavior:
library(usmap)
library(dplyr)
data(USArrests)
USArrests$full <- rownames(USArrests)
USA50 <- inner_join(us_map(), USArrests)
plot_usmap(data=USA50, values="Murder")
Error in [.data.frame
(result, , c(setdiff(names(result), names(data)), :
undefined columns selected
Expected behavior
A map appearing in the plot window
Screenshots
If applicable, add screenshots to help explain your problem.
Smartphone (please complete the following information):
usmap
version: [0.5.0]Additional context
Add any other context about the problem here.
Currently, the following does not work:
fips("NJ", county = c("Bergen", "Hudson"))
As it outputs the following:
#> [1] "34003"
#> Warning messages:
#> 1: In if (county_ == "") { :
#> the condition has length > 1 and only the first element will be used
#> 2: In name == county_ :
#> longer object length is not a multiple of shorter object length
#> 3: In name == paste(county_, "county") :
#> longer object length is not a multiple of shorter object length
It just results in the FIPS code of the first county entered in the vector, followed by a warning.
fips("NJ", county = c("Bergen", "Hudson"))
#> [1] "34003" "34017"
This would allow the ability to quickly convert a column of county names to a FIPS code in a data frame.
fips(state = c("NJ", "NY"), county = c("Bergen", "Hudson", "Westchester")
This would not work unless there was a direct mapping between the state
and county
parameters. In this case it would be easier to throw an error.
How could I plotting both state and county boundaries on the same map?
the following codes could run smoothly in the past,
counties_df <- us_map(regions = "counties", exclude = c("AK", "HI"))
states_df <- us_map(regions = "states", exclude = c("AK", "HI"))
ggplot() +
geom_polygon(data = counties_df,
aes(x = x, y = y, group = group),
fill = NA, color = "black") +
geom_polygon(data = states_df,
aes(x = x, y = y, group = group),
fill = NA, color = "red") +
coord_equal()
But now the two do not overlap. Is there anyway to fix this? Thank you so much!
Great package, thanks!
I request you add one or both of the following:
a) a data object (retrievable via utils::data()
) which returns all FIPs info
b) fips_info()
and/or fips()
returns all FIPS info when blank, or specifying states="all", etc.
Perhaps this feature is buried elsewhere?
Please provide metadata or information in the README (or elsewhere) which provides information on the frequency (preferably the times) at which the boundaries are updated.
Would also be really cool to have historical boundaries available (might increase probability of people using this package for time series visualizations of political boundary shifts, eg gerrymandering)
County map should be able to display labels just like state maps.
However, this require further consideration on how to display the labels since they would be much longer than state abbreviations (should "county" be omitted?, sizing, geom_text
vs geom_label
etc.).
The mapping vignettes (Mapping the US and Advanced Mapping) should include some examples of what is considered valid data and how data frames should be structured so that they can be used with plot_usmap
.
Describe the bug
As I understand it, currently the only way to have county data and state data in the same map is to create the maps separately, extract their layers and add it to a single ggplot object.
However, this method throws an error.
Simplest code to reproduce
ggplot() +
plot_usmap()$layers[[1]]
Error
Error in FUN(X[[i]], ...) : object 'x' not found
Environment:
Additional info
This method is also the only way to add multiple levels of data on the same map. So this should be looked into regardless of #26
Describe the bug
When plotting maps I get the following warnings:
Use of `map_df$x` is discouraged. Use `x` instead.
Use of `map_df$y` is discouraged. Use `y` instead.
Use of `map_df$group` is discouraged. Use `group` instead.`
To Reproduce
This is running in RStudio (R version 3.5.3) ggplot 3.3.0, and usmap 0.5.0
Additional context
Package still works as expected, would like to update code to avoid the warnings.
It seems that usmap is missing Shannon County, SD.
Running this...
usmap::fips(state= "SD", county = "Shannon")
...yields this error
Error in fips(state = "SD", county = "Shannon") :
Shannon is not a valid county in SD.
Expected behavior
Meanwhile, it works just fine for others:
usmap::fips(state= "SD", county = "Meade")
[1] "46093"
Environment:
version
output:platform x86_64-pc-linux-gnu
arch x86_64
os linux-gnu
system x86_64, linux-gnu
status
major 4
minor 1.3
year 2022
month 03
day 10
svn rev 81868
language R
version.string R version 4.1.3 (2022-03-10)
nickname One Push-Up
sessionInfo()
output:R version 4.1.3 (2022-03-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Rocky Linux 8.6 (Green Obsidian)
Matrix products: default
BLAS/LAPACK: /usr/lib64/libopenblasp-r0.3.15.so
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] parallel stats graphics grDevices utils datasets methods base
other attached packages:
[1] googlesheets4_1.0.0 ranger_0.13.1 showtext_0.9-5 showtextdb_3.0
[5] sysfonts_0.8.8 doParallel_1.0.17 iterators_1.0.14 vip_0.3.2
[9] usemodels_0.2.0 lubridate_1.8.0 foreach_1.5.2 yardstick_1.0.0
[13] workflowsets_0.2.1 workflows_0.2.6 tune_0.2.0 rsample_0.1.1
[17] recipes_0.2.0 parsnip_0.2.1 modeldata_0.1.1 infer_1.0.0
[21] dials_0.1.1 scales_1.2.0 tidymodels_0.2.0 RSocrata_1.7.11-2
[25] usmap_0.6.0 magrittr_2.0.3 broom_0.8.0 MASS_7.3-57
[29] patchwork_1.1.1 arrow_8.0.0 forcats_0.5.1 stringr_1.4.0
[33] dplyr_1.0.9 purrr_0.3.4 readr_2.1.2 tidyr_1.2.0
[37] tibble_3.1.7 ggplot2_3.3.6 tidyverse_1.3.1
loaded via a namespace (and not attached):
[1] googledrive_2.0.0 colorspace_2.0-3 ellipsis_0.3.2 class_7.3-20
[5] readtext_0.81 fs_1.5.2 rstudioapi_0.13 farver_2.1.0
[9] listenv_0.8.0 furrr_0.3.0 bit64_4.0.5 prodlim_2019.11.13
[13] fansi_1.0.3 xml2_1.3.3 codetools_0.2-18 splines_4.1.3
[17] cachem_1.0.6 jsonlite_1.8.0 dbplyr_2.2.0 compiler_4.1.3
[21] httr_1.4.3 backports_1.4.1 fastmap_1.1.0 assertthat_0.2.1
[25] Matrix_1.4-1 gargle_1.2.0 cli_3.3.0 tools_4.1.3
[29] gtable_0.3.0 glue_1.6.2 rappdirs_0.3.3 Rcpp_1.0.8.3
[33] cellranger_1.1.0 DiceDesign_1.9 vctrs_0.4.1 conflicted_1.1.0
[37] timeDate_3043.102 gower_1.0.0 globals_0.15.0 rvest_1.0.2
[41] mime_0.12 lifecycle_1.0.1 future_1.26.1 ipred_0.9-13
[45] vroom_1.5.7 hms_1.1.1 rematch2_2.1.2 curl_4.3.2
[49] memoise_2.0.1 gridExtra_2.3 rpart_4.1.16 stringi_1.7.6
[53] lhs_1.1.5 hardhat_1.0.0 lava_1.6.10 rlang_1.0.2
[57] pkgconfig_2.0.3 lattice_0.20-45 labeling_0.4.2 bit_4.0.4
[61] tidyselect_1.1.2 usmapdata_0.1.0 parallelly_1.32.0 plyr_1.8.7
[65] R6_2.5.1 generics_0.1.2 DBI_1.1.2 pillar_1.7.0
[69] haven_2.5.0 withr_2.5.0 survival_3.3-1 nnet_7.3-17
[73] future.apply_1.9.0 modelr_0.1.8 crayon_1.5.1 utf8_1.2.2
[77] tzdb_0.3.0 grid_4.1.3 readxl_1.4.0 data.table_1.14.2
[81] reprex_2.0.1 digest_0.6.29 openssl_2.0.2 GPfit_1.0-8
[85] munsell_0.5.0 viridisLite_0.4.0 askpass_1.1
Version 0.6.0
is currently failing several tests on certain platforms: https://cran.r-project.org/web/checks/check_results_usmap.html
Example:
Version: 0.6.0
Check: tests
Result: ERROR
Running 'testthat.R' [10s/14s]
Running the tests in 'tests/testthat.R' failed.
Complete output:
> library(testthat)
> library(usmap)
>
> test_check("usmap")
[ FAIL 2 | WARN 3 | SKIP 0 | PASS 163 ]
== Failed tests ================================================================
-- Failure ('test-plot.R:138'): singular regions can be used -------------------
plot_usmap(regions = "states")$layers not equal to plot_usmap(regions = "state")$layers.
Component 1: Component 12: Component 5: Component 21: Component 11: 1 string mismatch
Component 1: Component 12: Component 5: Component 21: Component 12: 1 string mismatch
Component 2: Component 12: Component 5: Component 21: Component 11: 1 string mismatch
Component 2: Component 12: Component 5: Component 21: Component 12: 1 string mismatch
-- Failure ('test-plot.R:140'): singular regions can be used -------------------
plot_usmap(regions = "counties")$layers not equal to plot_usmap(regions = "county")$layers.
Component 1: Component 12: Component 5: Component 21: Component 11: 1 string mismatch
Component 1: Component 12: Component 5: Component 21: Component 12: 1 string mismatch
Component 2: Component 12: Component 5: Component 21: Component 11: 1 string mismatch
Component 2: Component 12: Component 5: Component 21: Component 12: 1 string mismatch
[ FAIL 2 | WARN 3 | SKIP 0 | PASS 163 ]
Error: Test failures
Execution halted
Flavor: [r-devel-linux-x86_64-debian-clang](https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-clang/usmap-00check.html)
This must be fixed by November 21, 2022 or package will be removed from CRAN. Fix will be included in version 0.6.1
.
Input to usmap_transoform has many duplicate coords (but different other columns). The output of the function removes all the duplicate lat lon rows.
Auxiliary files for census shape data missing and need to be included in data
folder.
The function would take a data frame as input that contains two columns, the first representing longitude and the second representing latitude (column names don't matter).
The output will be a data frame containing the same data frame/coordinates except with the canonical usmap
projection applied to it:
CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs")
Function name: usmap_proj
Related issue: #13
For example:
# Plot New England region without Maine
plot_usmap("states", include = .new_england, exclude = "ME")
# Plot US map without Alaska and Hawaii (not cool)
plot_usmap("states", exclude = c("AK", "HI"))
For example:
plot_usmap("counties", size = 0.1)
US territories are frequently excluded from US maps. In the spirit of this package, which is to include often forgotten Alaska & Hawaii, it may be a good idea to allow the option to present the inhabited US territories on the map as well.
The territories being considered are:
These territories all have FIPS codes and official abbreviations so incorporating them into the data set should be seamless.
The difficult part will be moving the coordinates of these places so that they appear on the map in a suitable and aesthetically adequate part of the US map.
Update r-lib
based workflows to v2
versions.
These include setup-r
and setup-r-dependencies
used in test-coverage.yaml
and R-CMD-check.yaml
.
aes_string
aes_string
is soft-deprecated in ggplot2 according to https://ggplot2.tidyverse.org/reference/aes_.html, see warnings below.
โโ Warnings โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโ Warning ('test-plot.R:10'): (code run outside of `test_that()`) โโโโโโโโโโโโโ
Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
โน Please use `linewidth` instead.
Backtrace:
1. usmap::plot_usmap("counties", fill = "red")
at test-plot.R:10:0
3. ggplot2 (local) `<fn>`(fill = "red", color = "black", size = 0.4, mapping = `<uneval>`)
4. ggplot2::layer(...)
5. ggplot2:::deprecate_soft0(...)
โโ Warning ('test-plot.R:11'): (code run outside of `test_that()`) โโโโโโโโโโโโโ
`aes_string()` was deprecated in ggplot2 3.0.0.
โน Please use tidy evaluation ideoms with `aes()`
Backtrace:
1. usmap::plot_usmap(data = statepop, values = "pop_2015", color = "blue")
at test-plot.R:11:0
2. ggplot2::aes_string(x = "x", y = "y", group = "group", fill = values)
3. ggplot2:::deprecate_soft0("3.0.0", "aes_string()", details = "Please use tidy evaluation ideoms with `aes()`")
size
size
is deprecated in ggplot2 3.4.0 and has been replaced with linewidth
Fixes will be included in v0.6.1 release.
Currently the data frame which contains coordinates to draw the US state and county boundaries is stored within the usmap
package. This data should be extracted into a separate package that can be updated independently of usmap
. This will greatly reduce the file size of usmap
and will make it easier to develop for with the smaller footprint.
It will also prevent the following NOTE that currently appears during R CMD check (notice extdata
size compared to installed size):
> checking installed package size ... NOTE
installed size is 8.4Mb
sub-directories of 1Mb or more:
doc 1.6Mb
extdata 6.4Mb
usmap_data
, usmapd
, usmapdata
, ?) (#39 (comment))us_map
function) (#39 (comment))data-raw
folder) (#39 (comment))usmap
to make use of new package instead of internal data (#49)county-fips
or state-fips
files and currently there is no easily parseable document providing this information.The x and y in the US map look like they are UTM.
Is it possible to get lat long coordinates instead?
There should be an option in plot_usmap
to display state abbreviation labels (AK, AL, AR, etc.) in the center of each state polygon.
This may look something like this:
plot_usmap(data, ..., labels = true)
labels
would be the new parameter and accept true
or false
values (default being false
) indicating whether or not to display labels.
Another new option could be the ability to set label color.
Sent with GitHawk
usmap
has grown substantially in feature set since it was first released. The vignettes should be updated and added to such that all features are clearly explained and made accessible for new users.
Sent with GitHawk
Running usmap::usmap_crs()
results in the following warning:
Warning message:
In showSRID(uprojargs, format = "PROJ", multiline = "NO") :
Discarded datum unknown in CRS definition
The associated tests produce the following warnings:
test-transform.R:16: warning: data frame with AK and HI points is transformed
Discarded datum unknown in CRS definition
test-transform.R:16: warning: data frame with AK and HI points is transformed
CRS object has comment, which is lost in output
test-transform.R:16: warning: data frame with AK and HI points is transformed
Discarded datum Unknown based on Normal Sphere (r=6370997) ellipsoid in CRS definition
test-transform.R:16: warning: data frame with AK and HI points is transformed
CRS object has comment, which is lost in output
test-transform.R:16: warning: data frame with AK and HI points is transformed
Discarded datum Unknown based on Normal Sphere (r=6370997) ellipsoid in CRS definition
test-transform.R:32: warning: data frame with AK points is transformed
Discarded datum unknown in CRS definition
test-transform.R:32: warning: data frame with AK points is transformed
CRS object has comment, which is lost in output
test-transform.R:32: warning: data frame with AK points is transformed
Discarded datum Unknown based on Normal Sphere (r=6370997) ellipsoid in CRS definition
test-transform.R:48: warning: data frame with HI points is transformed
Discarded datum unknown in CRS definition
test-transform.R:48: warning: data frame with HI points is transformed
CRS object has comment, which is lost in output
test-transform.R:48: warning: data frame with HI points is transformed
Discarded datum Unknown based on Normal Sphere (r=6370997) ellipsoid in CRS definition
test-transform.R:64: warning: data frame with no AK or HI points is transformed
Discarded datum unknown in CRS definition
macOS 10.15.7
> version
_
platform x86_64-apple-darwin17.0
arch x86_64
os darwin17.0
system x86_64, darwin17.0
status
major 4
minor 0.2
year 2020
month 06
day 22
svn rev 78730
language R
version.string R version 4.0.2 (2020-06-22)
nickname Taking Off Again
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Catalina 10.15.7
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] usmap_0.5.1 rstudioapi_0.11 knitr_1.30 magrittr_1.5 maptools_1.0-2
[6] munsell_0.5.0 colorspace_1.4-1 lattice_0.20-41 R6_2.4.1 rlang_0.4.7
[11] tools_4.0.2 grid_4.0.2 gtable_0.3.0 xfun_0.18 tinytex_0.26
[16] htmltools_0.5.0 ellipsis_0.3.1 yaml_2.2.1 digest_0.6.25 tibble_3.0.3
[21] lifecycle_0.2.0 crayon_1.3.4.9000 ggplot2_3.3.2 vctrs_0.3.4 glue_1.4.2
[26] evaluate_0.14 rmarkdown_2.4 sp_1.4-2 pillar_1.4.6 compiler_4.0.2
[31] scales_1.1.1 foreign_0.8-80 pkgconfig_2.0.3
Since a transform is applied to the original shape file, the column headers lat
and long
for the map generated by us_map()
are not appropriate. Renaming them to x
and y
would make more sense.
I was surprised that fips_info
would sort and remove duplicates from the argument.
Current:
fips_info(c("21","20","20"))
abbr fips full
1 KS 20 Kansas
2 KY 21 Kentucky
Expected:
abbr fips full
1 KY 21 Kentucky
2 KS 20 Kansas
3 KS 20 Kansas
In other words
new_fips_info <- function(fips) if (length(fips)!=0)
merge(list(fips=fips), fips_info(), all.x=TRUE )
This comes up when I want the state name from the fips stored in df$fips
. I expected this to work within(df, state <- fips_info(fips)$full)
. Instead merge(df, fips_info(), all.x=T) %>% rename(state='full')
will do.
When looking up the FIPS code of a county, a state should be provided for ambiguous county names.
e.g.
Orange County, CA
Orange County, FL
Orange County, IN
Orange County, NY
Orange County, NC
Orange County, TX
Orange County, VT
Orange County, VA
There are now a lot more functions within usmap
than when the project was started. There should be some thought given to the naming of these functions going forward (before we reach a stable 1.0 release).
If the functions are to be changed, they will be renamed by v0.7.0
and the old function names will remain but be deprecated until v1.0.0
(where they will be removed).
Current Name | Proposed Name |
---|---|
fips |
|
fips_info |
|
map_with_data |
|
plot_usmap |
|
usmap_crs |
|
usmap_transform |
|
usmap |
Currently the data frame that is passed to usmap_transform
must have longitude in the first column and latitude in the second column. It might be more natural to allow columns in any order that have the names lon
/long
/longitude
and lat
/latitude
.
There can also be two optional parameters to specify the longitude/latitude column names.
For example:
If a data.frame contains columns "x" and "y" instead,
usmap_transform(data, longitude_name = "x", latitude_name = "y")
Currently the output data frame contains 4 columns: the two input columns followed by the two output columns. The output columns have the same name as the input columns but with a .1
appended to the end. This does not allow for intuitive use of the function as someone would have to inspect and notice the differences manually.
It might be better include an optional parameter that allows replacement of the input columns (i.e. input data frame has 2 columns named "lon" and "lat", and the output data frame has the same 2 columns, with data transformed). If all 4 columns are to be included in the output, a better convention might be to append _tf
or prefix transformed_
, etc. (TBD)
usmap/data-raw/maps/create-map-df.R
Line 32 in b3d285e
This is an important piece of projection info that will let others use other dataframes, for instance, having unprojected geographic data (i.e., lat/long coordinates) transform to the right spatial projection. I would include this in the intro/vignette part where you describe which projection is used (i.e., page 17 of https://cran.r-project.org/web/packages/usmap/usmap.pdf).
User should be able to add other shape file layers superimposed on the US map (e.g. roads, rivers, temperature data, etc.).
One way this could work is as follows:
roads <- # load shape file...
plot_usmap("counties") +
add_layer(roads) +
add_layer(...)
# etc.
This could work by applying the same spTransform
that was applied to the original US map data to the layers passed through to plot_usmap
.
Is your feature request related to a problem? Please describe.
There should be a way to plot both states and counties simultaneously. For example, plotting Alaska as a state with several Alaskan counties also outlined within them (possibly with different aesthetic features).
Describe the solution you'd like
This needs more thought but perhaps a boolean parameter to plot_usmap
indicating that the include
/exclude
parameters that are states should be plotted as states and counties should be plotted as counties (instead of just following what is defined in the regions
parameter).
Describe alternatives you've considered
Currently, the only way to achieve something like this is to create two separate plot_usmap
objects (one for the states and one for counties) and then combine them by extracting the $layers[[1]]
object from the plot_usmap
object which is both not ideal and could be unreliable if ggplot2
behavior were to be changed in a future update.
For example:
library(usmap)
library(ggplot2)
states <- plot_usmap("states", include = "CA")
counties <- plot_usmap("counties", include = "06073", color = "red")
ggplot() +
states$layers[[1]] +
counties$layers[[1]] +
counties$theme +
coord_equal()
For example:
plot_usmap(include = .new_england, exclude = "ME", labels = TRUE)
The label for Maine ("ME") will be displayed, despite the state being excluded.
Please add the proj and CRS to the README, and possibly also to each vignette.
See https://r-spatial.org/r/2022/04/12/evolution.html. From pkgapi analysis https://github.com/r-lib/pkgapi, this package uses elide()
methods, which is used in R/transform.R
. The maptools::elide()
methods could be moved to sp, but I don't know whether this is worth doing given the restricted use in this package and no detected use elsewhere.
The following documents need to be added to provide a way for new contributors to understand how to contribute and what is expected of them:
This is also to make the repository more complete. As part of this effort, the Wiki should be revamped as well.
Something in the merging process breaks the appearance of the map when plotted. Polygon points are mismatched causing extraneous lines to appear all over the map (especially in county map).
Passing in a vector (e.g. a list of state abbreviations) to fips
should result in a vector of the same length containing the respective FIPS codes.
A warning is presented, due to the non-vectorized nature of the internal code of fips
.
Attempt to pass a vector to fips
:
fips(c("AK", "AL", "AR"))
#> Warning message:
#> In if (!(state_ %in% abbr) & !(state_ %in% full)) { :
#> the condition has length > 1 and only the first element will be used
Rework the if-statements to check whether the input is valid. This can be done in conjunction with issue #7 and made into a much more robust system of checking whether the input is states, counties, abbreviations, names, etc.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.