Mixed network plot with geographical points on map while non geographical vertices outside the map - r

What I'm looking forward is something like this:
I want the geographical(29 states points in the case) presented on the maps, with a mass amount users out side it.
All the examples I've found with leaflet package, igraph and ggmaps package is merely edges on maps or networks beside map. The only idea I have is to give the non geographical vertices a set of restricted lat/lon coordinates, for examples throw them to the Antarctic Pole.
I think there may be some method better to solve the problems.

Related

Plot coastline and calculate distances (marmap and ggmap)

I am working on a research project in marine ecology, using R, and I would like to create a map of a small and precise part of the French Mediterranean coast. From this map I would like to add the different fish collection sites in order to calculate the distances between these sites, taking into account the topology of the coast (the sites being very close to the coast). I have used the marmap package to do this, however due to the size of the map I wish to create, the resolution is very poor and the map is unworkable.
data <- getNOAA.bathy(lon1 =2.97,lon2 =3.53,lat1 =41.9,lat2 =42.3,resolution = 1)
I would like to know if there is an alternative, such as using the ggmap package to get a map with a good resolution, then import the GPS points of the sites and calculate the distances between them using marmap ? Are the two packages compatible?
Do you have any other ideas?
I'd recommend using leaflet for mapping and geosphere to find the Haversine (as the crow flies` distance betwen points.

Voronoi approach to making districts while also using a multilinestring

I have a spatial objects with multiple points (buildings) on a map. What I wanted to do is divide an area based on the nearest point. The calculated Voronoi looks quite promising, but has some strange aspects if you know the "real world". For example a small part of a district is also at the other side of a river because of the closeness (surprise).
What I want to do is combine this with a multi linestring which contains rivers, railroads. What I want to do either end the district at this line OR add a penalty for 'crossing' it. Is anyone able to shed light on the problem, or possible suggest an alternative voronoi method that works?

Mapping how many points are within a radius of every location in R

In R, I am trying to create a choropleth map. I have built a database of businesses, some are part of chains (e.g. McDonalds) and others are independent. I want to calculate how many businesses are within 30km of each point on the map, but treat the different locations of chains as a single business.
For example, if you a point is:
5km from a McDonalds,
10km from Taco Bell
15km from Chick-Fil-A
20km from KFC
25km from McDonalds
35km from Five Guys
The colour will show that there are 4 fast food outlets within 30km.
I am happy to use any R package but I am mostly familiar with tmaps and ggplot2 maps.
At this stage the best approach I can think of is to create polygons for each chain and stack them as transparent layers of the same colour. I don't think this would be very efficient and wouldn't create a very nice looking choropleth.
The other answers I could find were either counting points (e.g https://gis.stackexchange.com/questions/229066/counting-how-many-times-a-point-is-inside-a-set-of-intersecting-polygons-in-r) or for GIS software.
EDIT:
I have managed to create a 30km radius from every location of every chain (using rgeos gIntersection). I now have a series of polygons.
To solve my question the additional thing I need to do is create polygons for where:
Only one polygon covers the area,
Two polygons covers the area,
etc.
To try to visual is this I used the answer from https://gis.stackexchange.com/questions/229066/counting-how-many-times-a-point-is-inside-a-set-of-intersecting-polygons-in-r
In the linked question they are trying to count how many polygons cover the numbered points (the image on the right). What I am trying to do is to create the image on the left, where there are polygons of no overlap (1), two overlapping polygons (2) and so on.
I think what you are trying to accomplish would be best approached using a raster approach rather than a chloropleth. To make a chorlopleth, you define a set of (generally irregular) polygons, summarize something within each polygon, then color the polygons based on the attributes. This would be a good approach if you wanted to say how many fast food resteraunts are within each state or county, or how many fast food joints per capita by state.
From your description, however, you are looking for how many fast food joints within a set radius for all points. This is more of a raster question, since you can represent your data on a regular grid.
The raster package is a good start for working with raster data and works well with the sf package.
You need to determine what density you need to accomplish your goal, then use this to determine the resolution of your raster. Once you've got that you can use raster::rasterize() to summarize your (I'm assuming) point data.
I'm assuming you have an object that has the locations of each restaurant, I'll call this object "points".
library(raster)
library(sf)
# create raster template with 30km resolution (I'm assuming your projection is in meters)
raster_template = raster((extent(points),
resolution = 30000,
crs = st_crs(points)
)
# rasterize your point data
r = rasterize(points, raster_template, fun = "count")
This should create a grid where each cell has the number of points within each 30km cell. You should then be able to plot the raster, but may want to either clip or mask it to just show parts that are within New Zealand

How to use the function r.cost to get the least-cost path between two polygons?

I am a beginner in GRASS but I would like to get the least-cost path between two polygons. More exactely, I would like to get the smallest cost from any point situated at the edge of one polygon (polygon A) to any point situated at the edge of another polygon (polygon B).
Until now, I used the function CostDistance and CostPath of ArcGIS by using a cost raster where each cell had a cost value, a shapefile for the first polygon, and a shapefile for the second polygon. I would like to do the same thing with GRASS. I think that the function r.cost allows to do this. But I don't know how to specify in parameters the two polygons in GRASS ?
Have you got an example of how to use r.cost with two polygons in R with package spgrass6?
Thanks very much for your help.
If the use of GRASS is not mandatory and sticking with R is sufficient, you should check the marmap package. Section 2.4 of the vignette (vignette("marmap")) is entitled:
2.4 Using bathymetric data for least-cost path analysis
The marmap package allows for computation of least-cost path constrained within a range of depth/altitude between any number of points. The two key functions here are trans.mat() to create a transition matrix similar to the cost-raster you mention. Then, lc.dist() computes the least-cost distance and allows to plot the path between points.
Detailed examples are provided in the marmap vignette.

Correctly compare areas from multiple parts of the globe using longitude and latitude

Here's my problem. I want to compare the area within multiple polygons in different parts of the world. I have the longitude and latitudes for each point of each polygon. My problem is that I don't know what projection to use to get x-y coordinates from the long-lat coordinates. I know OpenStreetMap has the projectMercator() function, but areas are known to inflate quite badly with latitude. (http://en.wikipedia.org/wiki/List_of_map_projections)
--> Do you guys know of an R function like projectMercator, that doesn't have such a distortion? I've been going over different types of projections in Wikipedia, but it's very unclear to me which is best for area comparisons, and then if those projections exist in R as functions (if they don't I'm fine hand coding them, though!)
Thanks!!!
Hillary

Resources