This is a quickstart guide to model and visualize animal movements from radio-telemetry data using the movetrack package.

library(movetrack)
library(ggplot2)
theme_set(theme_bw(base_size = 15))

# Load example data
data(motusData)

Estimate locations

The first step involves estimating animal locations based on antenna bearings and signal strength at two-minute intervals using the locate function.

loc <- locate(motusData, dTime = 2)
## Removed 10 detections containing missing values.

Model flight paths

Next, we model the animal’s flight paths using Markov Chain Monte Carlo (MCMC) with four parallel chains utilising the track function and return a summary of the results.

fit <- track(loc, parallel_chains = 4, refresh = 1e3)
## Running MCMC with 4 parallel chains...
## 
## Chain 1 Iteration:    1 / 2000 [  0%]  (Warmup) 
## Chain 2 Iteration:    1 / 2000 [  0%]  (Warmup) 
## Chain 3 Iteration:    1 / 2000 [  0%]  (Warmup) 
## Chain 4 Iteration:    1 / 2000 [  0%]  (Warmup) 
## Chain 3 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
## Chain 3 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
## Chain 1 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
## Chain 1 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
## Chain 4 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
## Chain 4 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
## Chain 1 Iteration: 2000 / 2000 [100%]  (Sampling) 
## Chain 1 finished in 143.0 seconds.
## Chain 3 Iteration: 2000 / 2000 [100%]  (Sampling) 
## Chain 3 finished in 143.2 seconds.
## Chain 4 Iteration: 2000 / 2000 [100%]  (Sampling) 
## Chain 4 finished in 154.8 seconds.
## Chain 2 Iteration: 1000 / 2000 [ 50%]  (Warmup) 
## Chain 2 Iteration: 1001 / 2000 [ 50%]  (Sampling) 
## Chain 2 Iteration: 2000 / 2000 [100%]  (Sampling) 
## Chain 2 finished in 348.1 seconds.
## 
## All 4 chains finished successfully.
## Mean chain execution time: 197.3 seconds.
## Total execution time: 348.2 seconds.
fit
Click to expand
##        ID                time  lon  lat distance  speed
## 1   49237 2023-08-20 20:16:00 8.80 54.8       NA     NA
## 2   49237 2023-08-20 20:18:00 8.80 54.8     1180   9.83
## 3   49237 2023-08-20 20:20:00 8.79 54.8     1430  11.92
## 4   49237 2023-08-20 20:22:00 8.79 54.8     1519  12.66
## 5   49237 2023-08-20 20:24:00 8.78 54.8     1584  13.20
## 6   49237 2023-08-20 20:26:00 8.77 54.8     1696  14.13
## 7   49237 2023-08-20 20:28:00 8.76 54.8     1902  15.85
## 8   49237 2023-08-20 20:30:00 8.75 54.8     2068  17.23
## 9   49237 2023-08-20 20:32:00 8.74 54.7     1977  16.48
## 10  49237 2023-08-20 20:34:00 8.74 54.7     1869  15.57
## 11  49237 2023-08-20 20:36:00 8.74 54.7     1785  14.88
## 12  49237 2023-08-20 20:38:00 8.75 54.7     1724  14.36
## 13  49237 2023-08-20 20:40:00 8.76 54.7     1614  13.45
## 14  49237 2023-08-20 20:42:00 8.77 54.7     1474  12.29
## 15  49237 2023-08-20 20:44:00 8.78 54.7     1392  11.60
## 16  49237 2023-08-20 20:46:00 8.79 54.7     1403  11.69
## 17  49237 2023-08-20 20:48:00 8.79 54.7     1577  13.15
## 18  49237 2023-08-20 20:50:00 8.80 54.6     1900  15.83
## 19  49237 2023-08-20 20:52:00 8.80 54.6     2253  18.77
## 20  49237 2023-08-20 20:54:00 8.81 54.6     2354  19.62
## 21  49237 2023-08-20 20:56:00 8.81 54.6     2256  18.80
## 22  49237 2023-08-20 20:58:00 8.82 54.6     2424  20.20
## 23  49237 2023-08-20 21:00:00 8.82 54.5     2806  23.39
## 24  49237 2023-08-20 21:08:00 8.83 54.5     3054   6.36
## 25  49237 2023-08-20 21:10:00 8.82 54.5     2746  22.89
## 26  49237 2023-08-20 21:12:00 8.82 54.5     2227  18.56
## 27  49237 2023-08-20 21:14:00 8.81 54.5     1898  15.82
## 28  49237 2023-08-20 21:16:00 8.79 54.4     1806  15.05
## 29  49237 2023-08-20 21:18:00 8.78 54.4     1722  14.35
## 30  49237 2023-08-20 21:20:00 8.77 54.4     1717  14.30
## 31  49237 2023-08-20 21:22:00 8.76 54.4     1864  15.54
## 32  49237 2023-08-20 21:24:00 8.75 54.4     2043  17.03
## 33  49237 2023-08-20 21:26:00 8.75 54.4     1899  15.82
## 34  49237 2023-08-20 21:28:00 8.75 54.4     1703  14.19
## 35  49237 2023-08-20 21:30:00 8.76 54.4     1638  13.65
## 36  49237 2023-08-20 21:32:00 8.76 54.3     1698  14.15
## 37  49237 2023-08-20 21:34:00 8.76 54.3     1787  14.89
## 38  49237 2023-08-20 21:36:00 8.77 54.3     1622  13.52
## 39  49237 2023-08-20 21:38:00 8.77 54.3     1453  12.11
## 40  49237 2023-08-20 21:40:00 8.77 54.3     1422  11.85
## 41  49237 2023-08-20 21:42:00 8.77 54.3     1537  12.81
## 42  49237 2023-08-20 21:44:00 8.77 54.3     1827  15.22
## 43  49237 2023-08-20 21:46:00 8.77 54.3     2172  18.10
## 44  49237 2023-08-20 21:48:00 8.77 54.2     2282  19.01
## 45  49237 2023-08-20 21:50:00 8.77 54.2     2555  21.29
## 46  49237 2023-08-20 21:52:00 8.76 54.2     2908  24.24
## 47  49237 2023-08-20 22:10:00 8.76 54.2     2816   2.61
## 48  49237 2023-08-20 22:12:00 8.75 54.1     2472  20.60
## 49  49237 2023-08-20 22:14:00 8.74 54.1     2049  17.08
## 50  49237 2023-08-20 22:16:00 8.73 54.1     2029  16.91
## 51  49237 2023-08-20 22:24:00 8.72 54.1     2296   4.78
## 52  49237 2023-08-20 22:26:00 8.71 54.1     2667  22.22
## 53  49237 2023-08-20 22:28:00 8.70 54.0     3337  27.81
## 54  49237 2023-08-20 22:30:00 8.69 54.0     4288  35.73
## 55  49237 2023-08-20 22:34:00 8.68 54.0     5338  22.24
## 56  49237 2023-08-20 23:00:00 8.66 53.9     5967   3.82
## 57  49237 2023-08-20 23:02:00 8.63 53.9     6737  56.14
## 58  49237 2023-08-20 23:04:00 8.59 53.8     7659  63.82
## 59  49237 2023-08-21 00:16:00 8.55 53.7     8269   1.91
## 60  49237 2023-08-21 00:18:00 8.50 53.7     8403  70.02
## 61  49237 2023-08-21 00:20:00 8.46 53.6     8064  67.20
## 62  49237 2023-08-21 00:22:00 8.40 53.5     7770  64.75
## 63  49237 2023-08-21 00:24:00 8.34 53.5     7712  64.26
## 64  49237 2023-08-21 00:26:00 8.28 53.4     7974  66.45
## 65  49237 2023-08-21 01:44:00 8.23 53.3     8041   1.72
## 66  49237 2023-08-21 01:46:00 8.18 53.3     7504  62.53
## 67  49237 2023-08-21 01:48:00 8.14 53.2     6458  53.82
## 68  49237 2023-08-21 01:50:00 8.11 53.2     5377  44.81
## 69  49237 2023-08-21 01:52:00 8.08 53.1     4476  37.30
## 70  49237 2023-08-21 01:54:00 8.06 53.1     3983  33.19
## 71  49237 2023-08-21 01:56:00 8.04 53.1     3737  31.14
## 72  50893 2023-10-26 18:38:00 8.78 54.3       NA     NA
## 73  50893 2023-10-26 18:40:00 8.78 54.3     4405  36.71
## 74  50893 2023-10-26 18:42:00 8.78 54.2     6218  51.82
## 75  50893 2023-10-26 18:44:00 8.79 54.2     7751  64.59
## 76  50893 2023-10-26 18:46:00 8.80 54.2     4112  34.27
## 77  50893 2023-10-26 18:48:00 8.81 54.2     3572  29.77
## 78  50893 2023-10-26 18:50:00 8.82 54.2     3510  29.25
## 79  50893 2023-10-26 18:52:00 8.84 54.2     3575  29.79
## 80  50893 2023-10-26 18:54:00 8.86 54.2     3816  31.80
## 81  50893 2023-10-26 18:56:00 8.87 54.1     4121  34.34
## 82  50893 2023-10-26 18:58:00 8.88 54.1     4687  39.06
## 83  50893 2023-10-26 19:00:00 8.88 54.1     4834  40.28
## 84  50893 2023-10-26 19:02:00 8.88 54.0     4685  39.04
## 85  50893 2023-10-26 19:04:00 8.86 54.0     4415  36.79
## 86  50893 2023-10-26 19:06:00 8.83 54.0     4024  33.53
## 87  50893 2023-10-26 19:08:00 8.77 54.0     4949  41.24
## 88  50893 2023-10-26 19:10:00 8.67 54.0     7375  61.46
## 89  50893 2023-10-26 19:12:00 8.52 53.9    12610 105.08
## 90  50893 2023-10-26 19:50:00 8.36 53.8    15503   6.80
## 91  50893 2023-10-26 19:52:00 8.24 53.7    13822 115.18
## 92  50893 2023-10-26 19:54:00 8.19 53.7     7916  65.97
## 93  50893 2023-10-26 19:56:00 8.15 53.6     5121  42.67
## 94  50893 2023-10-26 19:58:00 8.10 53.6     4492  37.43
## 95  50893 2023-10-26 20:00:00 8.07 53.6     3612  30.10
## 96  50893 2023-10-26 20:02:00 8.05 53.6     3440  28.67
## 97  50893 2023-10-26 20:04:00 8.05 53.6     3252  27.10
## 98  50893 2023-10-26 20:06:00 8.06 53.6     3297  27.47
## 99  50893 2023-10-26 20:08:00 8.08 53.6     3559  29.66
## 100 50893 2023-10-26 20:10:00 8.07 53.6     3380  28.16
## 101 50893 2023-10-26 20:12:00 8.00 53.7     6166  51.38
## 102 50893 2023-10-26 20:14:00 7.81 53.7    13844 115.37
## 103 50893 2023-10-26 20:16:00 7.75 53.7     5725  47.71
## 104 50893 2023-10-26 20:18:00 7.73 53.7     3616  30.13
## 105 50893 2023-10-26 20:20:00 7.65 53.7     6877  57.31
## 106 50893 2023-10-26 20:34:00 7.44 53.7    14080  16.76
## 107 50893 2023-10-26 20:36:00 7.26 53.7    12527 104.39
## 108 50893 2023-10-26 20:38:00 7.22 53.7     4200  35.00
## 109 50893 2023-10-26 20:40:00 7.22 53.7     3174  26.45
## 110 50893 2023-10-26 20:42:00 7.23 53.7     3059  25.49
## 111 50893 2023-10-26 20:44:00 7.23 53.7     3102  25.85
## 112 50893 2023-10-26 20:46:00 7.22 53.7     3115  25.96
## 113 50893 2023-10-26 20:48:00 7.20 53.6     3322  27.69
## 114 50893 2023-10-26 20:50:00 7.19 53.6     3340  27.84
## 115 50893 2023-10-26 20:52:00 7.16 53.6     3871  32.26
## 116 50893 2023-10-26 20:54:00 7.14 53.6     4039  33.66
## 117 50893 2023-10-26 20:56:00 7.13 53.6     4471  37.26
## 118 50893 2023-10-26 21:04:00 7.09 53.6     5633  11.74
## 119 50893 2023-10-26 21:06:00 7.08 53.5     4529  37.74
## 120 50893 2023-10-26 21:08:00 7.08 53.5     3494  29.12
## 121 50893 2023-10-26 21:10:00 7.08 53.5     3169  26.41
## 122 50893 2023-10-26 21:12:00 7.08 53.5     3075  25.63
## 123 50893 2023-10-26 21:14:00 7.08 53.5     3070  25.59
## 124 50893 2023-10-26 21:20:00 7.08 53.5     3692  10.26
## 125 50893 2023-10-26 21:22:00 7.09 53.5     3463  28.86
## 126 50893 2023-10-26 21:24:00 7.09 53.5     3508  29.23
## 127 50893 2023-10-26 21:26:00 7.08 53.5     5173  43.10
## 128 50893 2023-10-26 21:28:00 6.93 53.4    13121 109.34
## 129 50893 2023-10-26 21:30:00 6.51 53.3    30706 255.88
## 130 50893 2023-10-26 23:26:00 5.92 53.2    41820   6.01
## 131 50893 2023-10-26 23:28:00 5.36 53.1    40420 336.83
## 132 50893 2023-10-26 23:30:00 4.99 53.0    26287 219.06
## 133 50893 2023-10-26 23:38:00 4.84 52.9    12133  25.28
## 134 50893 2023-10-26 23:40:00 4.82 52.9     4531  37.76
## 135 50893 2023-10-26 23:42:00 4.83 52.9     3699  30.83
## 136 50893 2023-10-26 23:44:00 4.82 52.9     3462  28.85
## 137 50893 2023-10-26 23:46:00 4.81 52.9     3565  29.71
## 138 50893 2023-10-26 23:48:00 4.78 52.9     3857  32.14
## 139 50893 2023-10-26 23:50:00 4.76 52.9     3732  31.10
## 140 50893 2023-10-26 23:52:00 4.75 52.9     3691  30.75
## 141 50893 2023-10-26 23:54:00 4.74 52.9     3686  30.72
## 142 50893 2023-10-26 23:56:00 4.71 52.9     3823  31.86
## 143 50893 2023-10-26 23:58:00 4.68 52.8     3829  31.90
## 144 50893 2023-10-27 00:00:00 4.67 52.8     3604  30.03
## 145 50893 2023-10-27 00:02:00 4.67 52.8     3532  29.43
## 146 50893 2023-10-27 00:04:00 4.67 52.8     3587  29.90
## 147 50893 2023-10-27 00:06:00 4.64 52.8     4139  34.50
## 148 50893 2023-10-27 00:08:00 4.62 52.8     4162  34.69
## 149 50893 2023-10-27 00:10:00 4.60 52.8     3717  30.98
## 150 50893 2023-10-27 00:12:00 4.59 52.8     3564  29.70
## 151 50893 2023-10-27 00:14:00 4.59 52.8     3662  30.52
## 152 50893 2023-10-27 00:16:00 4.57 52.7     4985  41.54
## 153 50893 2023-10-27 00:18:00 4.55 52.7     8597  71.64
## 154 50893 2023-10-27 00:46:00 4.53 52.6     7481   4.45
## 155 50893 2023-10-27 00:48:00 4.53 52.6     5550  46.25
## 156 50893 2023-10-27 00:50:00 4.52 52.6     3961  33.01
## 157 50893 2023-10-27 00:52:00 4.52 52.6     3606  30.05
## 158 50893 2023-10-27 00:54:00 4.52 52.6     3598  29.98
## 159 50893 2023-10-27 00:56:00 4.53 52.6     3616  30.13
## 160 50893 2023-10-27 00:58:00 4.53 52.6     3717  30.97
## 161 50893 2023-10-27 01:00:00 4.53 52.6     4512  37.60

Plot flight speed

We can plot the results per individual and output variable using the plot function:

plot(fit, id = 49237)

Plot flight paths

We can visualise the results on a map using the mapTrack function:

mapTrack(fit) +
    geom_point(aes(recvDeployLon, recvDeployLat), data = motusData)
Modelled movement trajectories per individual. Posterior means are shown together with 50 posterior draws, circles on the map indicate receiver locations with detections of the animals.

Modelled movement trajectories per individual. Posterior means are shown together with 50 posterior draws, circles on the map indicate receiver locations with detections of the animals.

We could also create a Leaflet map using the following code:

library(sfheaders)
library(leaflet)

# Extract draws
draws <- getDraws(fit) |>
    sf_linestring("lon", "lat", linestring_id = "tID")

# Leaflet map
fit |>
    as.data.frame() |>
    sf_linestring("lon", "lat", linestring_id = "ID") |>
    leaflet() |>
    addTiles() |>
    addPolylines(data = draws, color = "grey", weight = 1, opacity = 0.2) |>
    addPolylines(color = ~ c("orange", "blue"))