Updated world map for R "maps" package? - r

library(maps)
1> map.where(database="world",29.392089,53.592505)
[1] "USSR"
does anyone know how I can get an updated world map database to drive this function in the maps package? I need country names only for now, not detailed sub-national administrative information such as is available in at gadm.org.

Try wrld_simpl in the maptools package.
require(maptools)
data(wrld_simpl)
plot(wrld_simpl)
## or subset based on the name
plot(wrld_simpl[wrld_simpl$NAME == "Russia", ])
## explore other attributes
summary(wrld_simpl)
I don't know how up to date it is, but ?wrld_simpl describes the source so you might find good stuff following links. Other packages that rely on sp will also be worth exploring for data.
Otherwise, there was the Rgshhs package, though I'm not sure that's still available. It came with fair detail but you can download more if you need it. It's a bit complicated, the original data is here: http://www.ngdc.noaa.gov/mgg/shorelines/gshhs.html
You can also read in data from vector formats (like MIF or SHP or PostGIS) using rgdal if you have your own data, or similar read functions in maptools for shapefile only.
Example to query the objects using points:
require(sp)
require(maptools)
data(wrld_simpl)
pts <- SpatialPoints(cbind(c(29.392089,147), c(53.592505, -35)), CRS(proj4string(wrld_simpl)))
over(pts, wrld_simpl)$NAME
For an introduction to these and other functions in sp see vignette("sp").
Also try the geonames package for more general querying of geographic names.

Related

Differences between readOGR and st_read

I am starting to work with R and shapefiles, I have seen that there are two ways to load a shapefile, readOGR and st_read....could you please explain to me what is the difference between both methods and which one is more recommended to work in GIS?
thanks in advance.
PD: I am a beginner in R, usually i work with arcGis or QGis.
this depends on whether you would like to work with sf or sp (I recommend the former). Both functions read in shapefiles, but st_read reads them as class sf and readOGR from rgdal reads them as sp.
I recommend reading up on sf, and using it instead of sp, but then again, it certainly depends on what you want to do.

Historic Maps in R

Being concerned with a spatial data analysis with data ranging from 1950 to 2016 I would like to plot some nice features in a world map in R. However, as the political landscape has changed with time, the actual implementations (e.g. the R package rworldmap) give the recent countries (Although, not long ago that was not true for all packages: Updated world map for R "maps" package?).
Hence my question is, whether there is some package with historic maps or otherwise some online-source for shapefiles or polygons for worldmaps, beginning in 1950.
Try the package cshapes from CRAN:
R Package for CShapes, a GIS dataset of country boundaries
(1946-2015). Includes functions for data extraction and the
computation of weights matrices.
It lets you extract a dataset for a chosen time, which you can then also use with any mapping tool you prefer.

Converting spatial polygon to regular data frame without use of gpclib tools

I working with spatial data in R for a commercial application and would like to use ggplot2 for data visualization. If you run the Hadley's example at https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles you find that in order to run the fortify command you need to enable the use of gpclib tools using gpclibPermit().
I'm looking for an efficient way (that doesn't involve manually hacking into the S4 object) to perform the same operation that fortify does here, i.e. take a spatial polygon object and turn it into a regular data frame where row entries contain latitudinal and longitudinal coordinates along with a polygon id.
Has anyone else solved this one?
You need to also install the rgeos package. When maptools is loaded and rgeos is not installed, the following message is shown:
> require("maptools")
Loading required package: maptools
Checking rgeos availability: FALSE
Note: when rgeos is not available, polygon geometry
computations in maptools depend on gpclib,
which has a restricted licence. It is disabled by default;
to enable gpclib, type gpclibPermit()
When fortify is called with a region argument (as it is in the example you linked to), then some "polygon geometry computations" need to be done. If rgeos is not available, and gpclib is not permitted, it will fail.

Exporting GIS line vector data (roads) to R with intention to use it for network K-function

I am still a beginner to R and I have the following problem. Any tips will be highly appreciated - it will be a big help to start off.
I have a road shapefile for one country in ArcGIS, that I would like to use as a network variable in R to apply network K-function (look for point randomness on the network using spatstat package). I have never worked with this type of problem before in R and I can't figure out how to convert the vector line dataset into network variable in R. I tried to used the shapefile package, but after reading the .shp, .shx and .dbf files, I don't know how it can be used any further.
The comments above are not correct.
In the spatstat package, first convert your shapefile to an object of class "psp" (planar segment pattern) as explained in the accompanying vignette on shapefiles.
Then use the function as.linnet to convert the "psp" object to a linear network object of class "linnet".
For more explanation, see chapter 17 of the spatstat book.

Map Data with R World Regions

Lately I have seen some cool examples of mapping in R and wanted to give this a shot. I currently have ArcView at work, but my spatial join is not working correctly (most likely user error).
Objective: I need a list of countries and what World Region they belong to. I have two layers (one country detail, the other region detail) and wanted to join the world region assignment onto each country. The join isn't working, so i figured I would come to the R community.
What are my options? This is my first attempt at doing any mapping in R and maybe there is an easier/better solution. Eventually I want to take lat/long data and map it as well.
Any insight will be much appreciated.
Brock
See the Spatial task view on CRAN, and packages like maps/mapdata, sp, rgdal, raster, blighty, rworldmap, RgoogleMaps, etc.
Do you have shapefiles you want to read? First get rgdal installed, or look at other options like maptools and shapefiles if that is difficult on your platform. Read functions in these packages will provide Spatial*DataFrame objects.
For information on the Spatial classes:
library(sp)
vignette("sp")
spatstat also has a lot of support for spatial data, and another vignette for converting to / from sp:
library(spatstat)
vignette("shapefiles")
The PBSmapping package is another good place to start. They have pretty extensive documentation and a great reference manual as well.

Resources