R Scripts

Play with spatial tools on 3D cells images

Let’s play with mapping tools on non-maps data ! {rayshader} is nice on raster maps, but what about using it on segmentized plant cell ? […] I wanted to find a good reason to play with Tyler Morgan-Wall packages for 3D visualisation of raster data: {rayshader} and {rayfocus}. Using cell …

Read more

Introduction to mapping with {sf} & Co.

At the “Rencontres R 2018” in Rennes, I proposed a brief introduction to mapping using the recent {sf} package and some other interesting packages. This blog post is an extended version of my presentation allowing me to share the code of the different maps that appeared on it. It’s still a brief …

Read more

Spatial correlation between rasters

In this blog article, I propose a way to look at the spatial repartition of correlation between two rasters. For your own reason, you may want to know the correlation between rasters, but a unique value issued from fonction cor is not enough. You would like to know if there are variations of …

Read more

Spatial interpolation on Earth as a 3D sphere

Earth map is usually presented flat. Geographical coordinates usually go from -180° to +180°. Spatial interpolations using coordinates may be tricky as -180° is equal to +180°. Here I propose a way to realize spatial interpolations on Earth as a sphere and then map the outputs in 3D using rgl. The …

Read more

Translation of rmarkdown documents using a data frame

In my post “Rmarkdown conditional chunks to create multilingual pdf and html with images”, I proposed a way to create a rmarkdown document to be printed in two different languages. If you deal with more than two languages, your document may become difficult to read. Moreover, if you work with …

Read more

SDMSelect: Cross-validation model selection and species distribution mapping

I decided to transform into a R package some R-scripts I have been using for years for my studies with species distribution modelling. I know it could be improved in many ways, but this v0.1 works as is. Please be kind for my first package ! And remember that it is a quick compilation of different …

Read more

Polygons tint band with leaflet and simple feature (library sf)

Stackoverflow is again a source of inspiration. I found this question on tint bands in leaflet, not related to R originally but I though I could answer it with R easily. This is also a good one for me to play with this new simple feature library sf and use it with leaflet. My simple solution is to …

Read more

How to fill a hatched area polygon with holes in leaflet with R

Drawing polygons filled with a hatched background is quite easy with classical plot in R. This only requires to define density and angle parameters of polygon function. SpatialPolygons from library sp also uses this polygon function. However, if you want to draw a hatched area of a SpatialPolygons …

Read more

Plot a specific image in a delimited polygon as repeated pattern on a map

A question on stackoverflow asked how to draw trees in a polygon to represent a forest area on a map. I first thought about plotting “emoji” on a regular point pattern sampled in the polygon. Library sp allows for sampling points in a delimited SpatialPolygons which was exactly what I was looking …

Read more

Rmarkdown conditional chunks to create multilingual pdf and html with images

In the upper output files, I list some of the tips I have to use to make this work and some bonus: […] I will modify this list if I face new difficulties or I find better ways to do things. […] The complete list of tips can be seen on the following web pages (embedded in iframes). Rmd …

Read more

Add multiple layers in leaflet widget with R

Library leaflet with R is well integrated with pipe writing (%>%). Thus, it is really easy to add multiple layers and options in a leaflet widget. If you want to add a lot of layers in your widget, it is not necessary to provide a “addPolygons” for each of these layers, you can simply use a loop. …

Read more

Rshiny expert image comparison app

I participated to a scientific publication on the analysis of plant cell images with a bio-image analyst Marion Louveaux. Part of the analysis was to define observation for each cell by visual expertise. The problem is that being able to observe the entire tissue when supposed to give an expertise …

Read more

Bayesian life cycle model: OpenBUGS code

The OpenBUGS code presented below is the additional material of a publication. This is the life cycle model of a marine species (the sole in the Eastern Channel). The Bayesian hierarchical model incorporates indices of juvenile spatialized abundance, larval dispersion, adult abundance indices and …

Read more

Mapping, spatial analyses and GIS with R

If you download the following presentation, you will find a presentation of different functions in the R-software useful for spatial data manipulations. Choosing the right libraries allows to create, import, modify, manipulate and map vector (shapefiles) or matrix (raster) spatial data. Your spatial …

Read more

Sensitivity of Inverse Community matrix

This script is the supplemental material of two publications on trophic network analyses. This allows to test for uncertainties of direct and indirect effects of small variation in biomass of a trophic network compartment on the rest of the ecosystem. […] Lassalle Geraldine, Bourdaud Pierre, …

Read more