World map with functional diversity values shown as coloured points or hexagons.
plot_fd_map <- function(df, lon_col = "lon", lat_col = "lat", value_col,
palette = "viridis", point_size = 0.8) {
if (!requireNamespace("rnaturalearth", quietly = TRUE))
install.packages("rnaturalearth")
library(ggplot2); library(rnaturalearth)
world <- ne_countries(scale = "medium", returnclass = "sf")
ggplot() +
geom_sf(data = world, fill = "#f5f5f0", colour = "#cccccc", linewidth = 0.2) +
geom_point(data = df,
aes(.data[[lon_col]], .data[[lat_col]],
colour = .data[[value_col]]),
size = point_size, alpha = 0.7) +
scale_colour_viridis_c(option = palette, name = value_col) +
coord_sf(expand = FALSE) +
theme_minimal() +
theme(axis.text = element_blank(), axis.ticks = element_blank(),
panel.grid = element_line(colour = "#eeeeee"))
}