This gallery shows several ways to use DonutMap. All locations, category values, and links are simulated for demonstration. They are not observed data.
Use donut_map() without flows when the goal
is to compare compositions at locations.
donut_map(
donut_data,
place,
category,
value,
lon = lon,
lat = lat,
map = study_area,
crs = 3347,
radius_range = c(18000, 52000),
colours = category_colours
) +
labs(
title = "Compositions only",
fill = "Category"
) +
theme(legend.position = "right")Supplying flows, from, to, and
flow_value draws links between donuts. The
flow_group and flow_colours arguments colour
the links and arrows by a categorical flow variable.
donut_map(
donut_data,
place,
category,
value,
lon = lon,
lat = lat,
map = study_area,
crs = 3347,
radius_range = c(18000, 52000),
colours = category_colours,
flows = flows,
from = from,
to = to,
flow_value = volume,
flow_group = corridor,
flow_colours = category_colours,
flow_curvature = 0.25,
flow_linewidth_range = c(0.3, 2.4),
flow_arrow = TRUE
) +
labs(
title = "Curved links coloured by corridor",
fill = "Donut category",
linewidth = "Volume"
) +
theme(legend.position = "right")Use flow_curvature = 0 for direct straight links. This
is often useful for small networks where curved trajectories would add
visual clutter.
donut_map(
donut_data,
place,
category,
value,
lon = lon,
lat = lat,
map = study_area,
crs = 3347,
radius_range = c(18000, 52000),
colours = category_colours,
flows = flows,
from = from,
to = to,
flow_value = volume,
flow_group = corridor,
flow_colours = category_colours,
flow_curvature = 0,
flow_linewidth_range = c(0.3, 2.4),
flow_arrow = TRUE
) +
labs(
title = "Straight links",
fill = "Donut category",
linewidth = "Volume"
) +
theme(legend.position = "right")donut_leaflet() creates a clickable leaflet
widget. The flow_min argument keeps only larger flows,
which can make dense networks easier to read.
donut_leaflet(
donut_data,
place,
category,
value,
lon = lon,
lat = lat,
map = study_area,
radius_range = c(18000, 52000),
colours = category_colours,
flows = flows,
from = from,
to = to,
flow_value = volume,
flow_group = corridor,
flow_colours = category_colours,
flow_min = 80,
flow_weight_range = c(1, 7),
flow_curvature = 0.25,
flow_arrow = TRUE,
flow_arrow_size = 35000,
flow_opacity = 0.8
)For more customized maps, compute the sf layers first
and then plot or transform them yourself.
donut_layer <- donut_polygons(
donut_data,
place,
category,
value,
lon = lon,
lat = lat,
crs = 3347,
radius_range = c(18000, 52000)
)
flow_layer <- flow_lines(
flows,
donut_data,
from,
to,
volume,
place,
group = corridor,
lon = lon,
lat = lat,
crs = 3347,
flow_curvature = -0.18,
flow_n = 50
)
ggplot() +
geom_sf(
data = flow_layer,
aes(linewidth = value, colour = group),
alpha = 0.7
) +
geom_sf(data = donut_layer, aes(fill = category), colour = "white") +
scale_colour_manual(values = category_colours) +
scale_fill_manual(values = category_colours) +
coord_sf(datum = NA) +
labs(
title = "Custom map from sf layers",
colour = "Flow group",
fill = "Donut category",
linewidth = "Volume"
) +
theme_minimal()