library(hexify)
# Sample data with counts
cities <- data.frame(
lon = c(16.37, 2.35, -3.70, 12.5, 4.9),
lat = c(48.21, 48.86, 40.42, 41.9, 52.4),
count = c(100, 250, 75, 180, 300)
)
result <- hexify(cities, lon = "lon", lat = "lat", area_km2 = 5000)
# Simple plot (uniform fill, no value mapping)
hexify_heatmap(result)
# \donttest{
library(ggplot2)
# With world basemap
hexify_heatmap(result, basemap = "world")
# Heatmap with value mapping
hexify_heatmap(result, value = "count")
# With world basemap and custom colors
hexify_heatmap(result, value = "count",
basemap = "world",
colors = "YlOrRd",
title = "City Density")
# Binned values with custom breaks
hexify_heatmap(result, value = "count",
basemap = "world",
breaks = c(-Inf, 100, 200, Inf),
labels = c("Low", "Medium", "High"),
colors = c("#fee8c8", "#fdbb84", "#e34a33"))
# Different projection (LAEA Europe)
hexify_heatmap(result, value = "count",
basemap = "world",
crs = 3035,
xlim = c(2500000, 6500000),
ylim = c(1500000, 5500000))
# Customize further with ggplot2
hexify_heatmap(result, value = "count", basemap = "world") +
labs(caption = "Data source: Example") +
theme(legend.position = "bottom")
# }
Run the code above in your browser using DataLab