这将完成这项工作,使用 ggplot2:
ggplot(df) +
# Split per elevator and floor
facet_grid(level~elevator, as.table=FALSE, labeller=label_both) +
# Add arrow "in" and its text
geom_segment(x=0, y=0, xend=2, yend=0, size=10, color="#A0C080",
lineend="butt", linejoin="mitre",
arrow=arrow(length=unit(.02, "native"), type="closed")) +
geom_text(aes(label=input), x=1, y=0, hjust=.5, size=8) +
# Add arrow "out" and its text
geom_segment(x=2, y=8, xend=0, yend=8, size=10, color="#C0B0B0",
lineend="butt", linejoin="mitre",
arrow=arrow(length=unit(.02, "native"), type="closed")) +
geom_text(aes(label=out), x=1, y=8, hjust=.5, size=8) +
# Draw floors
geom_rect(xmin=2.5, xmax=4, ymin=-4, ymax=12) +
# Graphical tweaks
theme_light() + theme(panel.grid=element_blank()) + ylim(-4,12) + xlim(-.5,3.5)
PS:如果您真的想包含计数为 0 的箭头,请将它们包含在您的数据框中或使用 tidyr::complete(...)(参见文档)