masking kernel density map by study region in rhr - raster

I have rhr-produced kernel density estimation of several marine species at the global scale. I want to mask these maps by the world map. However the resulting map is weird since latitude and logitude ranges are not same as a coordinate system.
An example output is same as below:
A kernel density map produced by rhr package, masked by global marine areas

Related

Trying to convert Numerical Values of Lat/Long into Spatial Data

I am working with a dataset that features chemical analyses from different locations within a cave, with each analysis ordered by a site number and that sites latitude and longitude. This first image is what I had done originally simply using ggplot.
Concentrations mapped by color over map
But what I want to do is use the shapefile of the cave system from which the data is sourced from and do something similar by plotting the points over the system and then coloring them by concentration. This below is the shapefile that I uploaded
Cave system shapefile
So basically I want to be able to map the chemical data from my dataset used to map the first figure, but on the map of the shapefile. Initially it kept on saying that it could not plot on top of it. So I figured I had to convert the latitude and longitude into spatial coordinates that could then be mapped on the shapefile.
Master_Cave_data <- Master_cave_data %>%
st_as_sf(MastMaster_cave_data, agr = "identity", coord = Lat_DD)
This was what I had thought to use in order to convert the numerical Latitude cooridnates into spatial data.

R: Species distribution modeling for a riverine species - all coordinates not falling in raster cells

I am running Species Distribution Modeling in R in biomod2 package for an riverine species in the Ganges River basin so I clipped the bioclim layer with the river network that I obtained from hydrosheds. Resolution of bioclim layer and river network at 1km*1km. But the problem arose as not all coordinates fell on the raster cells (probable causes - coordinates taken at banks, river networks not correctly delineated etc.)
So how do I overcome this problem? Do I pull the coordinates to the nearest raster cell (nearest in terms of vertices? - If this is the correct method than an easier way to do this too) or do I just leave the coordinates - more than half occurrence points would be deleted.
enter image description here

How to estimate density of Polygon intersections in R?

I have many polygons that represent search areas of different people. By intersecting all that areas I want to get density map - 1 person searched in this area, two in that area and so on.
My trouble is that I have >5k geoJSON polygons and I need to intersect all of them. Is there a way to do it R's sf package or (less preferably) in ArcGIS?

Interactive plot for spatial data in R markdown (to html)

So basically I have some spatial data, which I've found weighted matrix by distance dnearneigh in R and I am wondering if I can generate an interactive plot of the link distribution by changing the distance variable for the weighted matrix.
The data set:
CA.poly <- readShapePoly('CaliforniaCounty.shp')
This is a shapefile for California county and using this I can generate a weight matrix based on the distance of each county.
coords<-coordinates(CA.poly)
W_dist<-dnearneigh(coords,0,1.5,longlat = FALSE)
And after generating the matrix I can plot the link distribution by using:
plot(W_dist,coordinates(CA.poly))
This will show a network of counties where two counties are connected if their distance (between centroids) are less than 1.5 km.
All the codes are in a Rmd file and I am wondering is there a way to output in html an interactive plot where you (user) can change the distance parameter (change 1.5 km to 1 km for example) and the graph will change.
I looked up methods like using shiny and plotly but I don't think they suit my goal. Any suggestions?

Clustering geographical data in R

I'm new to R and would like to cluster geographical information using k-medoids. While accounting for curvature of the earth, I need to cluster on latitude, longitude, and depth.
My ultimate goal is to plot the colored data as a map.

Resources