用雷达图比较服务指标

这张图比较两个地点在两个报告期的四项指标。每条轴使用自己的单位,在前后两期保持同一量程。

每个地点在每个报告期各占一行。把各项指标的上下限按原单位写入 limits 表,再用 facet 分面比较两个报告期。虚线和菱形标出目标值,色带表示各项指标的参考范围。
library(ggforma)
library(ggplot2)
# Example indicators for two sites and two reporting periods.
scores <- data.frame(
site = rep(c("North", "South"), 2),
period = rep(c("Baseline", "Follow-up"), each = 2),
coverage = c(62, 72, 87, 78),
tests = c(540, 690, 910, 780),
timely = c(66, 58, 84, 72),
visits = c(240, 170, 310, 268)
)
scales <- data.frame(
axis = c("Coverage (%)", "Tests", "On time (%)", "Visits"),
lower = 0, upper = c(100, 1200, 100, 400)
)
names(scores)[3:6] <- scales$axis
axes <- scales$axis
targets <- c("Coverage (%)" = 75, Tests = 780, "On time (%)" = 75, Visits = 260)
bands <- transform(scales, lower = c(63, 620, 60, 200), upper = c(83, 940, 89, 320))
radar <- ggradar(scores, vars = all_of(axes), group = site, facet = period,
limits = scales, reference = targets, intervals = bands,
grid = "circle", fill = FALSE) +
labs(title = "How service profiles changed", colour = NULL,
caption = "Dashed outline and diamonds mark targets. Shading shows benchmark ranges.")
png_device <- function(filename, width, height, bg = "white", ...) {
ragg::agg_png(filename, width = width, height = height, units = "in",
res = 144, background = bg)
}
render_example <- function(file, device = png_device) {
ggsave(file, radar, width = 9.1, height = 4.35, units = "in",
device = device, bg = "white")
}
png.file <- file.path(tempdir(), "radar-profiles.png")
render_example(png.file)
png.file比较时,沿同一条轴读数。多边形的面积会随轴的顺序和量程改变。色带汇集的是各项指标各自的参考范围。