Можно сделать более элегантным, но, надеюсь, это решение поможет вам достичь дизайна, который вы ищете.
## variables related to heatmap squares
sz.square = 0.6
spacer = 0.05
col = c(completed="forestgreen", not_present="gray70", not_yet="orangered4",
wait_till_spring="skyblue2")
## variables related to plot layout
sz.rowlabels = 3
sz.collabels = 0.2
sz.legend = 4
## plotting functions for heat map triangles
plot.action = c(
## plot "viewed"
view = function(x, y, col) {
polygon(
c(
x - sz.square/2 + spacer,
x + sz.square/2,
x + sz.square/2),
c(
y + sz.square/2,
y - sz.square/2 + spacer,
y + sz.square/2),
col=col)
},
## plot "photographed"
photo = function(x, y, col) {
polygon(
c(
x - sz.square/2,
x + sz.square/2 - spacer,
x - sz.square/2),
c(
y + sz.square/2 - spacer,
y - sz.square/2,
y - sz.square/2),
col=col)
})
xlim = c(1 - sz.square - sz.rowlabels,
length(levels(progress$location)) + sz.square + sz.legend)
ylim = c(length(levels(progress$bird)) + sz.square,
1 - sz.square - sz.collabels)
## initialize the plot
par(mar=c(1, 1, 1, 1))
plot(c(0,2), c(2,0), type="n", xlim=xlim, ylim=ylim,
main=NA, xlab=NA, ylab=NA, xaxt="n", yaxt="n",
asp=1)
## plot heat map
for (i in 1:nrow(progress)) {
plot.action[[progress$action[i]]](
as.integer(progress$location[i]),
as.integer(progress$bird[i]),
col = col[progress$progress[i]])
}
## add axix labels
text(xlim[1], 1:nlevels(progress$bird), levels(progress$bird), adj=0, cex=2)
text(1:nlevels(progress$location), ylim[2], levels(progress$location),
adj=c(0.5,0), cex=2)
## legend
text(xlim[2] - sz.legend/2, ylim[2], "Legend", cex=2)
sz.square = 0.25
x.legend = rep(xlim[2] - 5/8*sz.legend, nlevels(progress$progress) + 2)
y.legend = ylim[2] + 1:(nlevels(progress$progress) + 2) * 0.35 + 0.2
plot.action[["view"]](x.legend[2], y.legend[2], col="white")
plot.action[["photo"]](x.legend[1], y.legend[1], col="white")
rect(
x.legend[3:length(x.legend)] - sz.square/2,
y.legend[3:length(y.legend)] - sz.square/2,
x.legend[3:length(x.legend)] + sz.square/2,
y.legend[3:length(y.legend)] + sz.square/2,
col=col)
text(x.legend + sz.square, y.legend,
c("viewed", "photographed", levels(progress$progress)),
adj=0, cex=1.3)
![enter image description here](https://i.stack.imgur.com/gyGmC.png)