Skip to content

Instantly share code, notes, and snippets.

@oliviergimenez
Created April 26, 2026 09:05
Show Gist options
  • Select an option

  • Save oliviergimenez/9ad8bbb69b82d7baca9c0b29d790fd4f to your computer and use it in GitHub Desktop.

Select an option

Save oliviergimenez/9ad8bbb69b82d7baca9c0b29d790fd4f to your computer and use it in GitHub Desktop.
dataviz for GPS data and home range
# fig 1: plot GPS data with color coding for tracking time
# fig 2: estimate and plot home range (AKDE) with package ctmm
#------ fig 1
# pakages
library(ctmm)
library(viridis)
library(ggplot2)
# data
data(buffalo)
# single individual
buf <- buffalo[[1]]
# convert in data.frame
df <- as.data.frame(buf)
# create variable for time (for gradient)
df$time_num <- as.numeric(df$t - min(df$t))
# plot
ggplot(df, aes(x = x, y = y, color = time_num)) +
#geom_point(size = 2, alpha = 0.9) +
#geom_point(size = 1.8, alpha = 0.8) +
geom_point(size = 2.2, alpha = 0.95) +
scale_color_viridis(
option = "plasma", # D ou magma
begin = 0,
end = 1,
name = "Tracking time",
breaks = range(df$time_num),
labels = c("Start", "End"),
guide = guide_colorbar(
ticks = FALSE,
title.position = "top",
title.hjust = 0.5
)
) +
coord_equal() +
theme_void() +
theme(
legend.position = "bottom",
legend.title = element_text(size = 12, hjust = 0.5)
) +
geom_path(alpha = 0.4, linewidth = 0.4)
#------ fig 2
# package
library(ctmm)
# data
data(buffalo)
DATA <- buffalo[[1]]
# initial guess
GUESS <- ctmm.guess(DATA, interactive = FALSE)
# select best model
FIT <- ctmm.select(DATA, GUESS, trace = FALSE)
# compute AKDE
UD <- akde(DATA, FIT)
# summary (area home range, etc.)
summary(UD)
# plot
plot(UD,
col.level = "black",
col.grid = NA,
col.DF = "black",
lwd = 2)
plot(DATA, col = "grey40", pch = 16, cex = 0.5, add = TRUE)
@oliviergimenez
Copy link
Copy Markdown
Author

Capture d’écran 2026-04-26 à 11 59 06

@oliviergimenez
Copy link
Copy Markdown
Author

Capture d’écran 2026-04-26 à 11 59 20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment