Legend

legend().

legend(). Base R only.

Goal

Run every block and confirm the chart is visible.

plot(1:4, c(48, 55, 92, 150), type = "b", col = "#0f6b52", ylim = c(0, 160), main = "Rain")
lines(1:4, c(22, 18, 40, 80), type = "b", col = "#c45c26")
legend("topleft", legend = c("Nairobi", "Mombasa"), col = c("#0f6b52", "#c45c26"), lty = 1)
print("legend")
barplot(c(21, 15, 15, 18, 12), names.arg = c("Nairobi", "Mombasa", "Kisumu", "Nakuru", "Eldoret"), col = "#0f6b52", main = "Units")
print("barplot")
set.seed(0)
hist(rpois(80, 12), main = "Units distribution", col = "#0f6b52", xlab = "units")
print("hist")
print("legend")