source("setup.R")

Here we will go over visualizing your data with maps. feedr includesa wrapper function that can be used to visualize your data on maps. This function, map_leaflet is really just a convenience function to do a lot of the grunt work. If you want to achieve a more fine tuned map, I suggest you check out the packages leaflet or mapview.

map_leaflet takes summarized presence and movement data and turns it into circles and paths around/between loggers representing time spent at different loggers and the amount of movement between particular logger paths. Because different projects may need different summaries (totals vs. means, corrected for number of individuals, uncorrected, etc.) we will first go over how to create the summary data and then pass this to the functions for plotting. This gives us more flexibility, but does mean that we have to do some work before we can visualize the data.

The companion package, feedrUI, also includes a stand-alone shiny app (launched with ui_animate()) that can be used to create simple animations of your data, this is a simple process as it does not require summarized data, but is also less flexible (see animations below).

Built-in Summaries

Let's start by calculating presence and movements:

v <- visits(finches_lg)
p <- presence(v)
m <- move(v)

There are many ways we can summarize the data. The following options are available through the summary argument of the mapping functions:

map_leaflet()

This function creates an interactive html map using leaflet for R (package leaflet).

map_leaflet(p = p, m = m, summary = "sum_indiv")

The map is interactive in that it can be zoomed, the tiles changed, and different elements added or removed. loggers (white-outlined black dots) can also be clicked on to reveal ids and circles and paths can clicked on to reveal their actual numbers.

You can also adjust some of the cosmetic details:

map_leaflet(p = p, m = m, summary = "sum_indiv",
            p_scale = 0.5, m_scale = 0.5,
            p_title = "Presence (min)", m_title = "Paths (Total use)",
            p_pal = c("blue","white"), m_pal = c("black","red"))

To plot by individual, simply use individual summaries:

map_leaflet(p = p, m = m, summary = "indiv")

Note, however, that for leaflet maps, the individual lines are stacked in order of magnitude and visualizations like this may not be very useful for large numbers of individuals.

To save this map, you can zoom and set it up as you like and use the "Export > Save as image" button in RStudio.


Back to top

Custom Summaries

Calculate total time present at each logger, corrected for the number of individuals total

p_pop <- p %>%
  group_by(logger_id) %>%
  summarize(amount = sum(length) / animal_n[1])
p_pop

We use animal_n[1] because we want to divide the total sum by the number of individuals in each experiment. However, the value animal_n is repeated, but we only need the first one, hence the [1].

If we wanted to calculate mean time present, we would use amount = mean(length)
If we wanted to calculate total time presence with no correction, we would use amount = sum(length)

Note: The new summary data set must have the column amount, regardless of how it is calculated. The mapping functions will look for that column name.

Now let's summarize the movement data for each movement path between loggers. We can summarize individually for each logger, which will account for the double counting (one row for leaving the logger and one row for arriving) as well as making sure we have logger_id in the final data set. We will also group by lat and lon, so they remain in the data set (because they are associated with logger_id they do not contribute any unique grouping combinations).

m_pop <- m %>%
  group_by(logger_id, move_path, lat, lon) %>%
  summarize(path_use = length(move_path) / animal_n[1])
m_pop

Note: The new summary data set must have the column path_use, regardless of how it is calculated. The mapping functions will look for that column name.

Specify summary = none when the data is already summarized:

map_leaflet(p = p_pop, m = m_pop, summary = "none")

We can also summarize data by individual for plotting of individual maps.

This is virtually identical to what we did above, except that we add one more variable to group by and we don't correct for the number of individuals:

p_indiv <- p %>%
  group_by(animal_id, logger_id) %>%
  summarize(amount = sum(length))
p_indiv

m_indiv <- m %>%
  group_by(animal_id, move_path, logger_id, lat, lon) %>%
  summarize(path_use = length(move_path))
m_indiv

Recap:

To create maps you need to define a summary OR create custom summaries with the following:

If you want to look at individual data, add animal_id to the groupings.

Animations

To look at animations of your data overtime, you can use the function ui_animate() to launch the animation shiny app included in the feedr package:

library(feedrUI)

ui_animate(v)

Here you can choose

The figure along the bottom shows the number of movements and/or bouts of presence over time. This can help you chose which time frames to include.


Back to top
Go back to home | Go back to transformations



animalnexus/feedr documentation built on Feb. 2, 2023, 1:12 a.m.