У меня есть следующий набор данных:
data = structure(list(Currency = c("\"AUD:Australian dollar\"", "\"BRL:Brazilian real\"",
"\"CAD:Canadian dollar\"", "\"CHF:Swiss franc\"", "\"CNY:Renminbi\"",
"\"EUR:Euro\"", "\"GBP:Pound (sterling)\"", "\"HKD:Hong Kong dollar\"",
"\"JPY:Yen\"", "\"TO1:Total (all currencies)\"", "\"USD:US dollar\""
), `1989` = c(NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_), `1992` = c(NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_),
`1995` = c("0.000001", "0.000001", "0.000001", "0.000001",
"0.000001", "0.000001", "0.000001", "0.000001", "0.000001",
NA, "0.000001"), `1998` = c("0.000001", "0.000001", "0.110001",
"1.765001", "0.000001", "0.000001", "2.075001", "0.000001",
"22.840001", "2243.970000", "2213.750000"), `2001` = c("0.000001",
"0.000001", "0.000001", "0.000001", "0.000001", "0.000001",
"0.000001", "0.000001", "0.000001", NA, "0.000001"), `2004` = c("0.000001",
"0.186183", "0.443694", "0.609938", "0.000001", "27.276067",
"0.977421", "0.000001", "1.807893", "695.878647", "676.367397"
), `2007` = c("0.027266", "0.247595", "0.688194", "1.008869",
"0.001477", "54.358328", "1.422906", "0.000170", "2.331012",
"1112.790520", "1078.012129"), `2010` = c("0.033014", "5.524377",
"0.899413", "1.362316", "0.003005", "331.224201", "1.042361",
"0.000935", "0.924893", "1612.849637", "1514.642008"), `2013` = c("0.057595",
"7.414087", "2.952866", "1.073223", "0.002421", "143.830218",
"0.957503", "0.000001", "1.842628", "1359.622210", "1283.970684"
), `2016` = c("0.009128", "2.535657", "0.767746", "0.644798",
"0.260262", "80.957156", "0.884905", "0.000001", "2.203361",
"1364.032088", "1324.969359"), `2019` = c("0.016027", "0.525830",
"0.525916", "0.556938", "0.921182", "44.797585", "1.325594",
"0.000001", "0.365471", "1874.424737", "1842.505958")), row.names = c(2L,
1L, 9L, 11L, 3L, 10L, 8L, 7L, 4L, 5L, 6L), class = "data.frame")
Когда я строю линии, я не могу получить внешнюю легенду, которая соответствует отображаемому цвету.
curr = data[,1]
years = colnames(data)[2:ncol(data)]
matplot(years,t(data[,2:ncol(data)]), type = "l")
legend(1,1,legend = curr, col = 1:length(years),text.width = 1)
Как можно добавить легенду? Спасибо