# Data
state_variables <- EDR_data$EDR1$abundance
d <- EDR_data$EDR1$state_dissim
# Coordinates in classic multidimensional scaling
x <- cmdscale(d, k = 3)
# Plot trajectories 1-10 in "coral", 11-20 in "blue" and 21-30 in "gold"
plot_edr(x = x, trajectories = state_variables$traj,
states = as.integer(state_variables$state),
traj.colors = c(rep("coral", 10), rep("royalblue", 10), rep("gold", 10)),
main = "type = 'trajectories'")
legend("bottomleft", legend = paste0("Trajectories ", c("1-10", "11-20", "21-30")),
lty = 1, col = c("coral", "royalblue", "gold"))
# Plot states with different colors depending on the state value
plot_edr(x = x, trajectories = state_variables$traj,
states = as.integer(state_variables$state),
traj.colors = NULL,
state.colors = rep(RColorBrewer::brewer.pal(5, "Blues"),
length(unique(state_variables$traj))),
type = "states", main = "type = 'states'")
legend("bottomleft", legend = paste0("State ", 1:5),
pch = 15, col = RColorBrewer::brewer.pal(5, "Blues"))
# Plot states with different colors depending on the abundance of sp1
plot_edr(x = x, trajectories = state_variables$traj,
states = as.integer(state_variables$state),
traj.colors = NULL, state.colors = viridis::viridis(5),
variable = state_variables$sp1,
type = "gradient", main = "type = 'gradient'", initial = TRUE)
legend("bottomleft",
legend = c(paste0("abun sp1 = ", min(state_variables$sp1)),
rep(NA, 28),
paste0("abun sp1 = ", max(state_variables$sp1))),
fill = viridis::viridis(30), border = NA, y.intersp = 0.2)
Run the code above in your browser using DataLab