Historic Maps in R - 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.

Related

R censusapi function introduces NAs

I am using R's censusapi package to download data from the US Census Bureau's Economic Census, specifically for 2012. Some of the columns read into R with NAs introduced by coercion, apparently because R assumes a data type that's inappropriate. In short, how do you integrate a getCensus API call with designated variable types?
Specifically, the variables "NAICS2012_TTL" and some cases of "NAICS2012" read in as NA, and shouldn't. The first is entirely a text field which R insists should be numeric. The second is a series of numbers that should be treated as text, and includes some cases of hyphenated numbers, which read in as NA. How can I tell R to fetch this data and not give it an inappropriate data type? Code follows. You'll need a Census API key to test:
library("censusapi")
myFile<-getCensus(name="ewks",vintage=2012,key=("YOURKEYHERE"),
vars = c("EMP","EMP_F","EMP_S","ESTAB","ESTAB_F","GEO_ID","GEO_TTL","GEOTYPE","NAICS2012","NAICS2012_TTL","OPTAX","PAYANN","PAYANN_F","PLACE"),region="place:*", regionin="state:01")
I have tried making myFile as a data.frame and specifying colClasses in the process, unsuccessfully. I have also read every support doc for the censusapi package I can find, to no avail.
After a few more hours of trial and error, I've concluded that the censusapi package is much better suited to the ACS data, and simply does not work well for the Economic Census data. To be clear, the Economic Census data is a Census Bureau data set that is supported by an API. However, the censusapi package converts some fields to NA for Economic Census data.
To more successfully read the Economic Census into R using its API, I turned to using the "curl" and "jsonlite" packages instead. Here is the script that worked. This is written to download NAICS code 22 data for all places. You use could an apply function to loop over the other NAICS codes.
library(curl)
library(jsonlite)
curl_download("https://api.census.gov/data/2012/ewks?get=EMP,NAICS2012_TTL,OPTAX,ESTAB,PAYANN,RCPTOT,GEO_TTL&for=place:*&NAICS2012=22 &key=YOURKEYHERE",naics_22)
mymatrix <- fromJSON(naics_22)
matrix2<-data.frame(mymatrix)
write.csv(matrix2,"EC22.csv")

Adding spatial clustering data in Map by R

I have the results for spatial clustering, in this results I have the id for some cities in USA. I would like to show this clustering results on a nice map. Is this feasible in R?
Yes, this is feasible.
You need to map the city ids to geographical data, then visualize it.
With the extensive drawing capabilities of R, this is not very hard; there are several R packages that will do the heavy lifting, and tutorials to guide you. Just pick whatever package you prefer.
We cannot give you a complete source, of course, because we don't know what kind of ids you have. For example many people use zip codes, others use FIPS ids, etc.

space-time clustering :: point patterns in different spaces

By following these instructions from Thomas I have created a ppp object using the spatstat package in R.
Because my data set includes a time dimension, I want to expand this analysis to consider the 3D space-time for clustering analysis.
The SPATSTAT VERSION 2 Preliminary Announcement 6th revision, dated 9th February 2010, suggests this should be possible with the new R package spatstat2. The announcement says:
The new class pp of point patterns will support:
multiple marks attached to each point
(e.g. trees can be marked by their species, diameter at breast height and leaf toxicity assay).
point patterns in different spaces, including 3D points, 2D space-time, 3D space-time, 1D networks in 2D space, different distance metrics
marks of ANY type
(each mark can be a window, a point pattern, a function etc etc)
However, beyond the announcement, I cannot find many additional details about the anticipated spatstat2 package. And I also cannot install the package from CRAN:
package ‘spatstat2’ is not available (for R version 3.0.3)
My questions are:
what are the best methods available in R for clustering analysis of events data (each event with geospatial coordinates X, Y, plus a Timestamp) ?
what has come to pass with the spatstat2 package ? Is it available ?
Thank you for your help!
Keith Helfrich
Regarding point 1:
I'm no expert on this, but I think the package stpp on CRAN could be useful.
Regarding point 2:
spatstat2 is definitely not available yet, and realistically it will not come out this year (personal correspondence with the authors).

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