Map Data with R World Regions - r

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.

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.

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.

How to compute distances along a network in shapefile? in R

I have a river network in a shapefile (class: "SpatialLinesDataFrame"), with some points on it (see picture below).
I would like to compute the distances between points, but along the rivers. I have been searching a lot and I am not able to find any function that allows directly that.
The closest thing I have found is the function "networkdistance" in the package "secrlinear", however I don't manage to transform my shapefile into the format required to use the function (a "linearmask" object).
Any help with this would be extremely appreciated.
Thanks in advance,
Tina.
I know this is an old thread, but just in case someone runs across this in the future: I just released an R package (riverdist) that deals with this issue, and also provides some tools for network editing and data summaries & visualization. It was written with fisheries work in mind, but could probably be applied to what you're working on, or at least that's the hope!
https://cran.r-project.org/web/packages/riverdist/vignettes/riverdist_vignette.html
Sorry this wasn't more timely -
I think we resolved this problem offline: the geographic coordinates (lat/long) of the shapefile needed to be projected before they could be used in secrlinear. That package approximates the linear network and uses igraph functions for distances.

Updated world map for R "maps" package?

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.

Can R be used for GIS? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I'd like to create some GIS plots, and I'm wondering if R can be used for this. Here are some examples of plots I'd similar in concept to those I'd like to make:
A temperature plot (or contour plot) of the United States, with color (or height) determined by state GDP. Thus, state boundaries would give discontinuities in the resulting plot.
A temperature plot of the United States where altitude is used for data. In this case, the resulting plot should vary smoothly across state boundaries.
The sum of the above 2 plots (with some scaling applied).
I'm just starting to learn R, and want to know if it would be the right tool for this kind of job. Looking at the coord_map of ggplot2, it looks like superimposing data onto the US is possible. But getting data to respect state boundaries could be very difficult.
Any advice?
First, you have the maps, mapproj and maptools packages, that give you a wide variety of map functions, projections, and so on to create about any map you can think of.
Then there is the sp package, which -among other things- allows you to plot any kind of data you load from the GADM database.
But most of all, there is the spatial projects page of R which gives you a whole lot more information, including links to mailing lists, to get going with R and spatial data. And if that's not enough, you have the CRAN Task View page for spatial data, listing 100+ packages to do what you want to do.
Think you had it now? There is more! Both books for sale and free blogs can help you finding out how to do what you want to do. And if you have some specific question, you can always come to StackOverflow , or use any of the mailing lists to get some more help.
So you see : This is R. There is no if. Only how. (Simon Blomberg)
powered by googling.
it still at alpha stage but the Rgis (composed of R packages terrain, RemoteSensing, gdistance ..) project look very promising. You can test the package on r-forge.
For raster data (DEM, altitude,...) handling there is the excellent raster package, and for other task like polygon clipping and more complicated stuff you can use rgeos (bidding of GEOS libs), maptools (for format exchange) or PBSmapping, and of course the sp package and the companion book Applied Spatial Analysis with R (Bivand, Pebsema and Rubio 2008) is a must.
On the other way, you can also link R to GIS like grass (spgrass6), saga (RSAGA), even QGIS and arcGIS but i don't use them.
finally you have to take a look at http://cran.r-project.org/web/views/Spatial.html
You might also want to look at this.
Integrating External programs with Modelbuilder
Using R in ArcGIS 10
and a thread
from Roger Bivand with useful links, advice, and some code for raster import.

Resources