Giter VIP home page Giter VIP logo

rnaturalearth's Introduction

CRAN status Project Status: Active – The project has reached a stable, usable state and is being actively developed. R-CMD-check

rnaturalearth

An R package to hold and facilitate interaction with Natural Earth map data.

This package provides :

  • access to a pre-downloaded subset of Natural Earth v4.1.0 (March 2018) vector data commonly used in world mapping

  • easy subsetting by countries and regions

  • functions to download other Natural Earth vector and raster data

  • a simple, reproducible and sustainable workflow from Natural Earth data to rnaturalearth enabling updating as new versions become available

  • clarification of differences in world maps classified by countries, sovereign states and map units

  • consistency with Natural Earth naming conventions so that rnaturalearth users can use Natural Earth documentation

  • data in sf or sv formats

The Natural Earth website structures vector data by scale, category and type. These determine the filenames of downloads. rnaturalearth uses this structure to facilitate download (like an API).

Install rnaturalearth

Install from CRAN :

install.packages("rnaturalearth")

or install the development version from GitHub using devtools.

devtools::install_github("ropensci/rnaturalearth")

Data to support much of the package functionality are stored in two data packages that you will be prompted to install when required if you do not do so here.

devtools::install_github("ropensci/rnaturalearthdata")
devtools::install_github("ropensci/rnaturalearthhires")

First usage

Here using plot as a simple, quick way to plot maps. Maps could also be made with ggplot2, tmap or other options. All retrieval functions accept an argument returnclass = "sf" to return package sf (Simple Features) or returnclass = "sv" (SpatVector) objects.

library(rnaturalearth)

# world countries
plot(ne_countries())
Warning: plotting the first 9 out of 168 attributes; use max.plot = 168 to plot
all

# uk
plot(ne_countries(country = "united kingdom"))
Warning: plotting the first 10 out of 168 attributes; use max.plot = 168 to
plot all

# states, admin level1 boundaries
plot(ne_states(country = "spain"))
Warning: plotting the first 9 out of 121 attributes; use max.plot = 121 to plot
all

Introductory vignette

vignette("rnaturalearth", package = "rnaturalearth")

To download Natural Earth data not already in the package

There are a wealth of other data available at the Natural Earth website. rnaturalearth has functions to help with download of these data.

The data available are outlined in the two tables below and online here.


category   cultural 

category   physical 

Specify the scale, category and type of the vector you want as in the examples below.

# lakes
lakes110 <- ne_download(scale = 110, type = "lakes", category = "physical")
plot(lakes110)

# rivers
rivers50 <- ne_download(
  scale = 50,
  type = "rivers_lake_centerlines",
  category = "physical",
  returnclass = "sf"
)

library(ggplot2)
library(sf)

ggplot(rivers50) +
  geom_sf() +
  theme_minimal()

Details of different country definitions and scales

vignette("what-is-a-country", package = "rnaturalearth")

Reproducible download of Natural Earth data into the package

Script used to get data into the accompanying data packages.

Acknowledgements

Thanks to Lincoln Mullen for code structure inspiration from USAboundaries, Hadley Wickham for comments and prompting, Bob Rudis for answers to stackoverflow questions about downloading Natural Earth data into R. The Natural Earth team and Nathan Kelso for providing such a great resource.

Potential future work

Potential additional data

Potential additional functions

  • facilitate joining of user data to country boundaries

  • facilitate subsetting by country groupings

    • e.g. least developed countries etc.

rnaturalearth's People

Contributors

andysouth avatar iantaylor-noaa avatar jeroen avatar karthik avatar khufkens avatar mps9506 avatar pmassicotte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rnaturalearth's Issues

'ne_download': add 'sv' (SpatVector) to 'returnclass' options

The 'terra' package is becoming widey used and it replaces not only 'raster' but also 'sp' (and 'rgdal'). So, it would be highly relevant to add the 'SpatVector' class to the ne_download 'returnclass' options, and eventually even have it replace the default 'sp' class when it becomes obsolete. Cheers!

Why all factor variables?

Why are all attributes factor variables in ne_countries?

> library("rnaturalearth")
> map_ne <- ne_countries()
> str(map_ne@data)
'data.frame':	177 obs. of  63 variables:
 $ scalerank : Factor w/ 2 levels "1","3": 1 1 1 1 1 1 1 2 1 1 ...
 $ featurecla: Factor w/ 1 level "Admin-0 country": 1 1 1 1 1 1 1 1 1 1 ...
 $ labelrank : Factor w/ 6 levels "2","3","4","5",..: 2 2 5 3 1 5 3 5 1 3 ...
 $ sovereignt: Factor w/ 171 levels "Afghanistan",..: 1 4 2 159 6 7 5 52 8 9 ...
 $ sov_a3    : Factor w/ 171 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 54 8 9 ...
 $ adm0_dif  : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 2 2 1 ...
 $ level     : Factor w/ 1 level "2": 1 1 1 1 1 1 1 1 1 1 ...
 $ type      : Factor w/ 5 levels "Country","Dependency",..: 5 5 5 5 5 5 4 2 1 5 ...
 $ admin     : Factor w/ 177 levels "Afghanistan",..: 1 4 2 165 6 7 5 54 8 9 ...
 $ adm0_a3   : Factor w/ 177 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ geou_dif  : Factor w/ 1 level "0": 1 1 1 1 1 1 1 1 1 1 ...
 $ geounit   : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 54 8 9 ...
 $ gu_a3     : Factor w/ 177 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ su_dif    : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ subunit   : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 54 8 9 ...
 $ su_a3     : Factor w/ 177 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ brk_diff  : Factor w/ 2 levels "0","1": 1 1 1 1 1 1 1 1 1 1 ...
 $ name      : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 56 8 9 ...
 $ name_long : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 56 8 9 ...
 $ brk_a3    : Factor w/ 177 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ brk_name  : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 55 8 9 ...
 $ brk_group : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
 $ abbrev    : Factor w/ 177 levels "Afg.","Alb.",..: 1 4 2 164 6 7 5 54 9 8 ...
 $ postal    : Factor w/ 172 levels "A","AE","AF",..: 3 5 4 2 7 8 6 149 9 1 ...
 $ formal_en : Factor w/ 174 levels "Arab Republic of Egypt",..: 38 68 73 169 2 74 NA 164 10 75 ...
 $ formal_fr : Factor w/ 4 levels "Nouvelle-Caldonie",..: NA NA NA NA NA NA NA NA NA NA ...
 $ note_adm0 : Factor w/ 6 levels "Commonwealth of U.S.A.",..: NA NA NA NA NA NA NA 3 NA NA ...
 $ note_brk  : Factor w/ 8 levels "Admin. by U.K.; Claimed by Argentina",..: NA NA NA NA NA NA 2 NA NA NA ...
 $ name_sort : Factor w/ 177 levels "Afghanistan",..: 1 4 2 166 6 7 5 57 8 9 ...
 $ name_alt  : Factor w/ 2 levels "East Timor","Islas Malvinas": NA NA NA NA NA NA NA NA NA NA ...
 $ mapcolor7 : Factor w/ 7 levels "1","2","3","4",..: 5 3 1 2 3 3 4 7 1 3 ...
 $ mapcolor8 : Factor w/ 8 levels "1","2","3","4",..: 6 2 4 1 1 1 5 5 2 1 ...
 $ mapcolor9 : Factor w/ 9 levels "1","2","3","4",..: 8 6 1 3 3 2 1 9 2 3 ...
 $ mapcolor13: Factor w/ 14 levels "-99","1","10",..: 12 2 11 8 6 3 1 4 12 9 ...
 $ pop_est   : Factor w/ 177 levels "-99","10057975",..: 72 20 95 118 104 76 96 26 52 160 ...
 $ gdp_md_est: Factor w/ 177 levels "-99","10040",..: 67 11 65 45 140 46 155 39 159 98 ...
 $ pop_year  : Factor w/ 2 levels "-99","0": 1 1 1 1 1 1 1 1 1 1 ...
 $ lastcensus: Factor w/ 27 levels "-99","1970","1979",..: 3 2 16 25 25 16 1 1 21 26 ...
 $ gdp_year  : Factor w/ 3 levels "-99","0","2009": 1 1 1 1 1 1 1 1 1 1 ...
 $ economy   : Factor w/ 7 levels "1. Developed region: G7",..: 7 7 6 6 5 6 6 6 2 2 ...
 $ income_grp: Factor w/ 5 levels "1. High income: OECD",..: 5 3 4 2 3 4 2 2 1 1 ...
 $ wikipedia : Factor w/ 2 levels "-99","0": 1 1 1 1 1 1 1 1 1 1 ...
 $ fips_10   : Factor w/ 0 levels: NA NA NA NA NA NA NA NA NA NA ...
 $ iso_a2    : Factor w/ 175 levels "-99","AE","AF",..: 3 6 4 2 8 5 7 153 10 9 ...
 $ iso_a3    : Factor w/ 175 levels "-99","AFG","AGO",..: 2 3 4 5 6 7 8 9 10 11 ...
 $ iso_n3    : Factor w/ 175 levels "-99","004","008",..: 2 6 3 159 8 13 4 57 9 10 ...
 $ un_a3     : Factor w/ 172 levels "-099","004","008",..: 2 5 3 156 7 12 1 1 8 9 ...
 $ wb_a2     : Factor w/ 171 levels "-99","AE","AF",..: 3 6 4 2 7 5 1 1 9 8 ...
 $ wb_a3     : Factor w/ 171 levels "-99","AFG","AGO",..: 2 3 4 5 6 7 1 1 8 9 ...
 $ woe_id    : Factor w/ 1 level "-99": 1 1 1 1 1 1 1 1 1 1 ...
 $ adm0_a3_is: Factor w/ 173 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ adm0_a3_us: Factor w/ 175 levels "AFG","AGO","ALB",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ adm0_a3_un: Factor w/ 1 level "-99": 1 1 1 1 1 1 1 1 1 1 ...
 $ adm0_a3_wb: Factor w/ 1 level "-99": 1 1 1 1 1 1 1 1 1 1 ...
 $ continent : Factor w/ 8 levels "Africa","Antarctica",..: 3 1 4 3 8 3 2 7 6 4 ...
 $ region_un : Factor w/ 7 levels "Africa","Americas",..: 4 1 5 4 2 4 3 7 6 5 ...
 $ subregion : Factor w/ 22 levels "Antarctica","Australia and New Zealand",..: 18 10 19 21 16 21 1 14 2 22 ...
 $ region_wb : Factor w/ 8 levels "Antarctica","East Asia & Pacific",..: 7 8 3 5 4 3 1 8 2 3 ...
 $ name_len  : Factor w/ 16 levels "10","11","12",..: 2 13 14 9 16 14 1 10 16 14 ...
 $ long_len  : Factor w/ 21 levels "10","11","12",..: 2 18 19 11 21 19 1 15 21 19 ...
 $ abbrev_len: Factor w/ 8 levels "10","3","4","5",..: 3 3 3 5 3 3 3 1 3 4 ...
 $ tiny      : Factor w/ 5 levels "-99","2","3",..: 1 1 1 1 1 1 1 2 1 1 ...
 $ homepart  : Factor w/ 2 levels "-99","1": 2 2 2 2 2 2 2 1 2 2 ...

I guess this might be related to "keep the data as close as possible to Natural Earth", but character and numeric make so much more sense, IMHO.

Also missings (-99, -099 (see un_a3)), should be coded as NA, IMO.

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rnaturalearth_0.1.0 pacman_0.4.1       

loaded via a namespace (and not attached):
[1] tools_3.3.2     sp_1.2-4        grid_3.3.2      lattice_0.20-34

ne_download() not working properly

Hi,
I discovered this package in Hadley Wickham's book, and I think it's very useful.
I've been playing with it a bit since yesterday, and it turns out that ne_download() can't download everything that's listed in the help page.
I have tried airports, ports, railroads and they won't work (I get a 404 or a timeout error).
The command I used is :
ne_download(category="cultural", type="airports")

It works fine for populated places though.
Any idea why ?

Extract out common check_scale function

Something like this:

check_scale <- function(x) {
  if (is.numeric(x) && length(x) == 1) {
    if (x %in% c(110, 50, 10)) 
      return(x)
  } else if (is.character(x) && length(x) == 1) {
    x <- c(small = 110, medium = 50, large = 10)[tolower(x)]
    if (!is.na(x))
      return(unname(x))
  }

  stop("Invalid `scale`. Must be [110, 50, 10, 'small', 'medium', 'large']", 
    call. = FALSE)

}

check_scale(110)
check_scale("small")

I personal don't think you need to allow "110" as a valid input

'ne_download': check if map already exists in 'destdir'

It could save a lot of time and energy if ne_download first checked if a file is already in 'destdir' before downloading it. If it is, the function could just import the map that's already there. (Or you could add an argument to optionally re-download and overwrite the map if explicitly wanted.) Cheers!

Italy - changes in provinces in Sardegna region

Hi,

I am working with Italy data, and I noticed that the provinces of Sardegna region in Italy are not updated:

> italy_map <- rnaturalearth::ne_states(country = "Italy", returnclass = "sf") %>%
    dplyr::filter(region == "Sardegna")
> italy_map$name %>% unique %>% sort
[1] "Cagliari"          "Carbonia-Iglesias" "Medio Campidano"   "Nuoro"            
[5] "Ogliastra"         "Olbia-Tempio"      "Oristrano"         "Sassari" 

On 2016, the provinces Carbonia-Iglesias, Medio Campidano, and some part of Cagliari were merged into new province - South Serdinia (source (Wikipodia)[https://en.wikipedia.org/wiki/Province_of_South_Sardinia]).

Therefore, when plotting Italy provinces, with the new provinces setting, this is the results:

image

Thanks,
Rami

ne_download() no longer working, curl requires referrer URL to be set

ne_download() recently started running into a HTTP status was '500 Internal Server Error' error. This appears to be the same issue as outlined here on the Natural Earth GitHub repo: nvkelso/natural-earth-vector#434

The fix apparently requires setting the "referrer URL", which can be done with curl as follows:

curl -e 'https://www.naturalearthdata.com/downloads/110m-cultural-vectors/' -I https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_boundary_lines_land.zip

However, it's not clear to me how to do this with download.file() in R.

Document related datasets in one file

e.g.

#' World country polygons from Natural Earth.
#' 
#' @name countries
NULL

#' @format A \code{SpatialPolygonsDataFrame} with 177 elements
#' @source \url{http//www.naturalearthdata.com/download/}
#' @rdname coutries
"countries110"

Note that roxygen will automatically supply:

#' @docType data
#' @keywords dataset
#' @usage data(countries50)

so you can drop them

breakaway_disputed_areas at scale10 is HTTP 404

Because as of right now the file is actually called

ne_10m_admin_0_disputed_areas.zip

without the breakaway_, inconsistent with other scales.

The workaround is to give the type as admin_0_disputed_areas and ignore the warnings.

Install issues

Recently I had several times problems when a student had to use the function ne_countries (scale = 10). The rnaturalearth package was installed correctly, but it required to install again without resolving the issue. It seems that the pacckage "rnaturalearthhires" fail to download or install. I don't know why. Any thoughts about this?

Thanks!

ne_download URL strange/wrong

So after clean install using the latest "rnaturalearth" on Windows 7 (R 3.5.3):

The URL seems strange to me:
http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip

Command that I ran:
countries10 <- ne_download(scale = 10, type = 'countries', category = 'cultural', returnclass = "sf")

Error in utils::download.file(file.path(address), zip_file <- tempfile()) : cannot open URL 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_countries.zip'
2.
utils::download.file(file.path(address), zip_file <- tempfile())
1.
ne_download(scale = 10, type = "countries", category = "cultural", returnclass = "sf")

Coastline rendering with World Robinson (etc) projection

Not sure if this is a bug exactly. But I'm wondering about getting a clean coastline plot with the 110 scale. E.g., this looks fine:

coastlines <- rnaturalearth::ne_coastline(scale = 100, returnclass = "sf")
ggplot() + geom_sf(data = coastlines)  +
  cowplot::theme_minimal_grid()

Whereas these do not because of the scale and the wrapping at the edges.

ggplot() + geom_sf(data = coastlines) + 
  coord_sf(crs = sf::st_crs("ESRI:54030")) +
  cowplot::theme_minimal_grid()


ggplot() + geom_sf(data = coastlines) + 
  coord_sf(crs = sf::st_crs("ESRI:54009")) +
  cowplot::theme_minimal_grid()

These render fine at scale=50. Any tips for a clean plot at scale=110 and crs 54030 appreciated.

Provide updated data list

  • a function that returns up to date list/dataframe of vector data sources with filenames that can be used in ne_download()

  • check_data_exist() could cross reference against this instead of the csv that is manually updated currently.

My suggestion is to use httr and the Github API to checking folders in the Natural Earth Repo.

Switzerland map - typo on the postal field?

Hi, I am trying to use the ne_states function to pull the Switzerland map information and to merge it with canton data I have. I am using the postal field and I think there is a typo with the value of Canton of Obwalden that should be OW as oppose of NW which represents Canton of Nidwalden:

rnaturalearth::ne_states(country = "Switzerland", returnclass = "sf") %>% 
  dplyr::filter(postal == "NW") %>% dplyr::select(postal,woe_label, woe_name, gn_a1_code)

Simple feature collection with 2 features and 4 fields
geometry type:  MULTIPOLYGON
dimension:      XY
bbox:           xmin: 8.0437264 ymin: 46.758774 xmax: 8.5632296 ymax: 47.011291
epsg (SRID):    4326
proj4string:    +proj=longlat +datum=WGS84 +no_defs
  postal                            woe_label  woe_name
1     NW Canton of Nidwalden, CH, Switzerland Nidwalden
2     NW  Canton of Obwalden, CH, Switzerland  Obwalden
  gn_a1_code                       geometry
1      CH.NW MULTIPOLYGON (((8.4651477 4...
2      CH.OW MULTIPOLYGON (((8.3681511 4... 

Thanks,
Rami

Is or isn't Crimea part of Russia?

This is not (only) a political issue, but rather a call for consistency in the rnaturalearth database.

Indeed, this is what happens at the small scale.

library(ggplot2)
library(sf)
library(rnaturalearth)

ggplot() + 
  geom_sf(data=ne_countries(scale='small', returnclass = 'sf'), size = 0.2) + 
  geom_sf(data=ne_countries(scale = 'small', country = 'Russia', returnclass = 'sf'), fill = 'red') +
  coord_sf(xlim = c(25,45), ylim = c(40,50))

image

And this is what happens at the medium and large level.

image
image

The reason can't simply be that Crimea is a small area disregarded by the small scale, as Kaliningrad Oblast is correctly included at all levels, despite having a smaller surface than Crimea (15000 vs 27000 km²).

image

I am in no position to suggest the best action to take. I can only suggest to have a look at the solution proposed by the OpenStreetMap Data Working Group or to simply follow the relevant UN resolution.

Supplemental river and lake centerlines not available

Thank you for the wonderful package.

I am not able to download the 10m river and lake centerline North American supplemental file.

check_data_exist(scale = 10, category = "physical", type = "rivers_north_america")

Returns:

[1] FALSE
Warning message: In check_data_exist(scale = 10, category = "physical", 
type = "rivers_lake_north_america") :   rivers_north_america seems not to be in the list 
for category=physical maybe try the other category of c('cultural', 'physical')

The file location is: https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/physical/ne_10m_rivers_north_america.zip

The regular rivers_lake_centerline download works for me, but is not the file I'm after:

check_data_exist(scale = 10, category = "physical",  type = "rivers_lake_centerlines")

Any insight would be appreciated. Cheers.

install of hires data glitch...

Hi, great package, just wanted to mention a glitch in installing the hires data...

When running the following code:
mex_sf <- ne_states(country="Mexico", returnclass = "sf")

I'm asked to install the hires data...but upon trying to do so I get an error message: "Connection not found".

I went to this repo and followed the readme code:

install.packages("rnaturalearthhires",
                 repos = "http://packages.ropensci.org",
                 type = "source")

This also didn't work. I got several different error messages but largely centered around "no connection".

When using the following, everything installs without any trouble:
devtools::install_github("ropensci/rnaturalearthhires")

Suggest editing the README so the install info matches the above. I'm not sure why the other option via install.packages breaks, but with devtools no problem.

I'm using R 4.0.3, on Mojave 10.14.6 and have the most updated {sf} and {rnaturalearth} versions.

Missing countries from the data set

Would it be possible to include / update for the inclusion of the following countries in the data set? I cannot see them in the following call:

world_map <- ne_countries(returnclass = "sf")

Country ISO3 Code
Andorra AND
Antigua and Barbuda ATG
Bahrain BHR
Barbados BRB
Cabo Verde CPV
Dominica DMA
Grenada GRD
Holy See VAT
Kosovo XKX
Liechtenstein LIE
Maldives MDV
Malta MLT
Mauritius MUS
Monaco MCO
Saint Kitts and Nevis KNA
Saint Lucia LCA
Saint Vincent and the Grenadines VCT
San Marino SMR
Seychelles SYC
Singapore SGP

How to use `ne_states()` with `ggplot()`

Is it possible to use the data from ne_states() with ggplot2?

From the documentation it seems like its only "out of the box computable" with base R's plot() function.

I'm asking because ne_countries() seems to work pretty well and is pretty easy to read as far as output is concerned because its a tibble is outputted. ne_states() returns a list which is hard to understand exactly what needs to be passed as arguments to work with ggplot.

world_map <- ne_countries(scale = "large", returnclass = 'sf')
europe_map <- world_map %>% filter(continent=="Europe")
ggplot() + 
    geom_sf(data = europe_map) +
    coord_sf(xlim = c(-25, 45), ylim = c(33, 73), expand = FALSE)+
    theme_void()

image

Thanks!

coastline problem when using world projection

Hi @andysouth, thank you for building rnaturalearth it's a great tool to draw great maps quickly.

I'm currently having a issue using worldwide coastline with certain projections. It may not be due to the package, but you maybe aware of a solution to this problem. When plotting world coastline with projections I get a weird line between each part of the world because of Russian coastline:
Here's a reprex:

library("ggplot2")

# No problem
ggplot() +
    geom_sf(data = rnaturalearth::ne_coastline(returnclass = "sf"))

# Problem with Russian coastline
ggplot() +
    geom_sf(data = rnaturalearth::ne_coastline(returnclass = "sf")) +
    coord_sf(crs = sf::st_crs(3395))

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  French_France.1252          
#>  tz       Europe/Paris                
#>  date     2018-05-18
#> Packages -----------------------------------------------------------------
#>  package           * version    date      
#>  backports           1.1.2      2017-12-13
#>  base              * 3.5.0      2018-04-23
#>  class               7.3-14     2015-08-30
#>  classInt            0.2-3      2018-04-16
#>  colorspace          1.3-2      2016-12-14
#>  compiler            3.5.0      2018-04-23
#>  curl                3.2        2018-03-28
#>  datasets          * 3.5.0      2018-04-23
#>  DBI                 1.0.0      2018-05-02
#>  devtools            1.13.5     2018-02-18
#>  digest              0.6.15     2018-01-28
#>  e1071               1.6-8      2017-02-02
#>  evaluate            0.10.1     2017-06-24
#>  ggplot2           * 2.2.1.9000 2018-05-15
#>  graphics          * 3.5.0      2018-04-23
#>  grDevices         * 3.5.0      2018-04-23
#>  grid                3.5.0      2018-04-23
#>  gtable              0.2.0      2016-02-26
#>  htmltools           0.3.6      2017-04-28
#>  httr                1.3.1      2017-08-20
#>  knitr               1.20       2018-02-20
#>  lattice             0.20-35    2017-03-25
#>  lazyeval            0.2.1      2017-10-29
#>  magrittr            1.5        2014-11-22
#>  memoise             1.1.0      2017-04-21
#>  methods           * 3.5.0      2018-04-23
#>  mime                0.5        2016-07-07
#>  munsell             0.4.3      2016-02-13
#>  pillar              1.2.2      2018-04-26
#>  plyr                1.8.4      2016-06-08
#>  R6                  2.2.2      2017-06-17
#>  Rcpp                0.12.16    2018-03-13
#>  rlang               0.2.0      2018-02-20
#>  rmarkdown           1.9        2018-03-01
#>  rnaturalearth       0.1.0      2017-03-21
#>  rnaturalearthdata   0.1.0      2017-02-21
#>  rprojroot           1.3-2      2018-01-03
#>  scales              0.5.0.9000 2018-05-03
#>  sf                  0.6-3      2018-05-17
#>  sp                  1.2-7      2018-01-19
#>  spData              0.2.8.3    2018-03-25
#>  stats             * 3.5.0      2018-04-23
#>  stringi             1.2.2      2018-05-02
#>  stringr             1.3.1      2018-05-10
#>  tibble              1.4.2      2018-01-22
#>  tools               3.5.0      2018-04-23
#>  udunits2            0.13       2016-11-17
#>  units               0.5-1      2018-01-08
#>  utils             * 3.5.0      2018-04-23
#>  withr               2.1.2      2018-05-03
#>  xml2                1.2.0      2018-01-24
#>  yaml                2.1.19     2018-05-01
#>  source                            
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  Github (tidyverse/ggplot2@daba7ab)
#>  local                             
#>  local                             
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  Github (hadley/scales@d767915)    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)                    
#>  local                             
#>  Github (jimhester/withr@79d7b0d)  
#>  CRAN (R 3.5.0)                    
#>  CRAN (R 3.5.0)

us county shapefile?

hi there,

i was trying to get a shapefile with usa counties delineated. is there anything like this available in this package? thanks

review

@karthik @hadley @hrbrmstr

Would you be able to take a quick look at rnaturalearth ?

Is it useful ? Is it as useful as it could be ?

The readme describes what I'm aiming for. Broadly quick access to a subset of data and a function to download other. Have I gone too far in including too many datasets making it too big ?

Thanks

(I'm away for a couple of weeks after tomorrow.)

ne_download bug?

Hi all,

This works:

ne_download(scale = 50, type = 'breakaway_disputed_areas', category = 'cultural')

But this does not

ne_download(scale = 10, type = 'breakaway_disputed_areas', category = 'cultural')

According to the first table on this page, it should do I believe?

https://docs.ropensci.org/rnaturalearth/

image

Cheers, Jim

Error installing rnaturalearthhires

Hi, I'm having trouble installing rnaturalearthhires. Any help that could be provided would be much appreciated.

Reproducible example is below.

library(rnaturalearth)

world <- ne_countries(scale = "large", returnclass = "sf")
The rnaturalearthhires package needs to be installed.
Install the rnaturalearthhires package?

1: Yes
2: No

Selection: 1
Installing the rnaturalearthhires package.
Error in value[3L] :
Failed to install the rnaturalearthhires package.
Please try installing the package for yourself using the following command:
install.packages("rnaturalearthhires", repos = "http://packages.ropensci.org", type = "source")

install.packages("rnaturalearthhires", repos = "http://packages.ropensci.org", type = "source")
Error in install.packages : error reading from connection

Session info is as follows:

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] rnaturalearth_0.1.0

loaded via a namespace (and not attached):
[1] Rcpp_1.0.8 magrittr_2.0.2 units_0.8-0 tidyselect_1.1.2 lattice_0.20-45 R6_2.5.1 rlang_1.0.1 fansi_1.0.2
[9] dplyr_1.0.8 tools_4.1.2 grid_4.1.2 KernSmooth_2.23-20 utf8_1.2.2 cli_3.2.0 e1071_1.7-9 DBI_1.1.2
[17] ellipsis_0.3.2 class_7.3-19 assertthat_0.2.1 tibble_3.1.6 lifecycle_1.0.1 sf_1.0-6 crayon_1.5.0 purrr_0.3.4
[25] vctrs_0.3.8 glue_1.6.2 sp_1.4-6 proxy_0.4-26 compiler_4.1.2 pillar_1.7.0 generics_0.1.2 classInt_0.4-3
[33] pkgconfig_2.0.3

Initial install

Hi,

Excited to play around with the package. Possibly an error on my end, but it seems that the current set up for first time installation has some issues with auto installing the dependencies, specifically httr and DBI.
Errors:

  • Installation failed: there is no package called ‘httr’
    and
  • Error: package or namespace load failed for ‘rnaturalearth’:
  • object ‘dbExecute’ is not exported by 'namespace:DBI'

I manually installed both and am now up and running.

  • Nick

Problem loading data for Czechia and Bosnia and Herzegovina

I just ran into a little hiccup trying to load data for Czechia/Czech Republic:

library(rnaturalearth)
map_europe <- ne_countries(continent = "Europe")
map_europe$name[8] # this contains "Czech Rep."
# [1] "Czech Rep."
map_cz <- ne_countries(country = "Czech Rep.") # does not work
# Error in ne_countries(country = "Czech Rep.") : 
#  No such country (Czech Rep.) in the data
map_cz <- ne_countries(country = "Czechia") # does not work either
# Error in ne_countries(country = "Czechia") : 
#  No such country (Czechia) in the data

In this blog entry https://www.naturalearthdata.com/blog/miscellaneous/natural-earth-v4/ it says Czechia was now used. Maybe this switch broke something? Or am I overlooking something?

Edit: I experienced a similar problem for Bosnia and Herzegovina.

library(rnaturalearth)
map_europe <- ne_countries(continent = "Europe")
map_europe$name[5] # this contains "Bosnia and Herz."
# [1] "Bosnia and Herz."
map_bh <- ne_countries(country = "Bosnia and Herz.") # does not work
# Error in ne_countries(country = "Bosnia and Herz.") : 
#  No such country (Bosnia and Herz.) in the data

Thanks a lot for this otherwise fantastic package!

ne_countries() with returnclass = "sf" crashes in CentOS 7 Linux

ne_countries() function in rnaturalearth version 0.2.0 under R version 4.0.1 on a Linux server:

Operating System: CentOS Linux 7 (Core)
Architecture: x86-64

crashes:

  > world <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf")
 
  *** caught segfault ***
 address (nil), cause 'unknown'
 
 Traceback:
  1: CPL_crs_from_input(x)
  2: make_crs(x)
  3: st_crs.character(x@projargs)
  4: st_crs(x@projargs)
  5: st_crs.CRS(x@proj4string)
  6: st_crs(x@proj4string)
  7: append(lst, list(crs = st_crs(x@proj4string), precision = precision))
  8: do.call(st_sfc, append(lst, list(crs = st_crs(x@proj4string),     precision = precision)))
  9: structure(sfc, bbox = bb)
 10: handle_bbox(do.call(st_sfc, append(lst, list(crs = st_crs(x@proj4string),     precision = precision))), x)
 11: st_as_sfc.SpatialPolygons(sp::geometry(x), ...)
 12: st_as_sfc(sp::geometry(x), ...)
 13: st_as_sf.Spatial(x)
 14: st_as_sf(x)
 15: ne_as_sf(spdf[filter, ], returnclass)
 16: rnaturalearth::ne_countries(scale = "medium", returnclass = "sf")
 
 Possible actions:
 1: abort (with core dump, if enabled)
 2: normal R exit
 3: exit R without saving workspace
 4: exit R saving workspace

Using returnclass = "sp" works but is not what is needed.

Downloading directly from this repo (using the remotes package) did not help.

France is missing

This happens both with the CRAN and the devtools versions of this package.

eu_sf <- ne_countries(scale = 50, returnclass = 'sf')
eu_sf %>% dplyr::filter(iso_a2 == 'FR') %>% nrow()
[1] 0

Is the same with iso_a3 or other fields. France is missing. It is instead present when the scale is 110.

transfer to ropensci

👋 @andysouth we no longer transfer onboarded packages to ropenscilabs but instead directly to ropensci so we should move this repo. Are you ok with my doing it? If so when would you have the time to update all links? I wouldn't transfer before you have time to do that, and it's not urgent to transfer anyway.

I see these two repos would need to be transferred at the same time:

If possible could you please add this badge to the README of rnaturalearth when updating CI links?
[![Project Status: Active – The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)

Thanks for your patience! 😺

returnclass='sf' as default

The sf package is becoming more and more popular. It is also a successor of the sp pacakge.
Perhaps it is a good idea to change a returnclass default argument to 'sf'?

Fail install in Ubuntu20 LTS and Rv4.0

I have this error installing:

> install.packages("rnaturalearth")
Installing package into ‘/home/enrique/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
probando la URL 'https://cloud.r-project.org/src/contrib/rnaturalearth_0.1.0.tar.gz'
Content type 'application/x-gzip' length 193162 bytes (188 KB)
==================================================
downloaded 188 KB

* installing *source* package ‘rnaturalearth’ ...
** package ‘rnaturalearth’ successfully unpacked and MD5 sums checked
** using staged installation
** R
** data
*** moving datasets to lazyload DB
** inst
** byte-compile and prepare package for lazy loading
double free or corruption (out)
Aborted (core dumped)
ERROR: lazy loading failed for package ‘rnaturalearth’
* removing ‘/home/enrique/R/x86_64-pc-linux-gnu-library/4.0/rnaturalearth’
Warning in install.packages :
  installation of package ‘rnaturalearth’ had non-zero exit status

The downloaded source packages are in
	‘/tmp/RtmpmXEHFd/downloaded_packages’
Warning in install.packages :
  converting NULL pointer to R NULL`

With the github version is the same problem. Thanks.

rnaturalearth installation error

Good day, I tried a function call using ne_countries and got the could not find function error. I then tried to install rnaturalearth, but that gave me another error. Screen shots of the error and my system specs are attached. Thanks!

Screenshot 2020-12-03 at 00 57 50

Screenshot 2020-12-03 at 00 58 43

Screenshot 2020-12-03 at 00 58 52

Listing available country names

To my surprise ne_countries(country = "United States") or ne_countries(country = "USA") do not work but ne_countries(country = "United Kingdom") does.

I searched countries110 and found "United States" as a country descriptor so I thought it was a bug, rather than just the fact that I had to type ne_country(country = "United States of America"). It is unclear which field should be used for specifying country names, and it seems odd to require the full formal name for the USA but not for the United Kingdom of Great Britain and Northern Ireland or the Commonwealth of Australia, etc.

Thanks for a great package!

link between rnaturalearth and rnaturalearthdata pre CRAN submission

@sckott
Finally found time to try to submit rnaturalearth to CRAN (apologies for delay).

Just to remind you. The plan recommended by Lincoln Mullen was :

rnaturalearth CRAN
rnaturalearthdata CRAN
rnaturalearthhires rOpenSci drat repo (already there)

Because I want to submit rnaturalearth & rnaturalearthdata together I get no errors & warnings locally, but when submitting to win-builder I get.
4 ERRORs, 1 WARNING, 3 NOTEs
e.g.
The rnaturalearthdata package needs to be installed.
Error in install_rnaturalearthdata() :
Failed to install the rnaturalearthdata package.

https://win-builder.r-project.org/DXH5l7715FOc/00check.log

Can you suggest how best to fix ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.