Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Using R shiny and R markdown, an interactive document was created. Bird data from the Marine Projects Geoserver are plotted. The point data can be shown as grids using two different types of grids. Bird species, type of grid, and resolution of the grid can be chosen interactively.

Below a screen shot of the interactive page, the interactive document can be found here:httpshttp://gammarusal-206.shinyapps.io/Interactive_gridding/xtr.deltares.nl:3838/deltares/InteractiveGridBirds/

The code is found in the right panel.

Note that this is a shiny application, a shiny server is necessary to facilitate the interactivity.

For more information: willem.stolte@deltares.nl

 

 

 

Code Block
themeConfluence
titleR shiny interactive web page
---
title: "Gridding of bird data"
author: "Willem Stolte"
date: "January 11, 2016"
output: html_document
runtime: shiny
---

## The bird data set

The data used are bird counts from the Dutch coastal waters. Data are obtained from [the marine projects geoserver](http://marineprojects.openearth.nl/geoserver) by WFS. The data are available as number of individuals encountered for each species, at a given point and time. 

When "Hexagonal grid" or "Rectangular grid" is selected, the data are on the fly converted to grids. The grid cells obtain a value based on the number of times that a particular species was encountered in that grid cell (indpendent on how many individuals were counted per occasion). 

```{r, message=F, warning=F, comment=F, echo = F}
require(readr) #(faster and simpler read functions than the standard functions)
require(ggplot2)
require(rworldmap)
require(scales)
require(hexbin)
```

```{r, message=F, warning=F, comment=F, echo = F}
birds <- read_csv("http://marineprojects.openearth.nl/geoserver/ihm_viewer/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=ihm_viewer:shwoz_vogels&outputFormat=csv", col_types = "_ddi___c______ccc__cc_di_")
data("countriesLow")

world <- fortify(countriesLow)
map <- ggplot() + geom_polygon(data = world, 
                               aes(x=long, y=lat, group=group), 
                               color = "lightgrey", fill = "darkgrey")
xxlim <- expand_range(c(min(birds$Longitude),max(birds$Longitude)), add = 0.2)
yylim <- expand_range(c(min(birds$Latitude),max(birds$Latitude)), add = 0.4)

```

In the interactive plot below, the original point data are shown when "point" is chosen. Data can be converted to hexagonal and rectangular grids. The resolution of the converted grids can be chosen, as well as bird species. 

```{r, echo=F, message=F, warning=F, comment=F, fig.width=10, fig.height=10, fig.align = "left"}
inputPanel(
  selectInput("soort", label = "species:",
              choices = unique(birds$Biotaxon.naam), selected = "Larus fuscus"),
  radioButtons("type", label = "Type:",
               c("Original points" = "point", "Hexagonal grid" = "hex", "Rectangular grid" = "rect")),
  sliderInput("resolution", label = "Resolution:",
              min = 0.05, max = 1, value = 0.2, step = 0.05)
)

renderPlot({
  birds_soort <- subset(birds, birds$Biotaxon.naam == input$soort)
  map = map + coord_equal(, xlim = xxlim, ylim = yylim)
  if(input$type == "rect")  {
    map = map + geom_bin2d(data = birds_soort, aes(Longitude, Latitude, fill = (..count..)), binwidth = as.numeric(c(input$resolution,input$resolution)))
  }
  if(input$type == "hex")  {
    map = map +stat_bin_hex(data = birds_soort, aes(Longitude, Latitude, fill = (..count..)), binwidth = as.numeric(c(input$resolution,input$resolution)))} 
  if(input$type == "point")  {
    map = map + geom_point(data = birds_soort, aes(Longitude, Latitude, fill = log10(Numeriekewaarde)), alpha = 0.4, shape = 21, color = "white", size = 2)
    }
  map = map + ggtitle(paste("")) +
    scale_fill_gradient(low = "blue", high = "red") +  # limits=c(0,50), breaks=seq(0, 40, by=10), 
    scale_color_gradient(low = "blue", high = "red") +  
    theme(axis.text = element_blank(),
          axis.title = element_blank(),
          axis.line = element_blank(),
          axis.ticks = element_blank())
  map
})
```

Voor meer informatie: [Willem Stolte](mailto: willem.stolte@deltares.nl), Deltares