R将一个图例添加到法国地图

时间:2017-06-05 21:55:53

标签: r maps legend

您好,我只想在此地图上添加一个图例,代表法国各部门年轻女性的生育力: enter image description here

使用此代码:

library(raster)

fr <- getData(country='France',level=2)

classes <- c('0-1','1-1.5','1.5-2','2-3')

fr$fertility <- sample(seq(1,3,0.1),length(fr),replace = T)

fr$fertgroups[fr$fertility <=1] <-1 
fr$fertgroups[fr$fertility > 1 & fr$fertility <=1.5] <-2 
fr$fertgroups[fr$fertility > 1.5 & fr$fertility <=2] <-3 
fr$fertgroups[fr$fertility > 2 & fr$fertility <=3] <- 4 

fr$cols <- c('red','orange','yellow','green')[fr$fertgroups]

plot(fr,col=fr$cols)

我不知道如何添加这个传奇。

2 个答案:

答案 0 :(得分:1)


plot(fr, col=fr$cols)
legend("topright", as.character(unique(fr$fertgroups)), fill = unique(fr$cols))

答案 1 :(得分:0)

locator(n=1)
legend(-6.780717,45.01717,legend=classes,
fill=fr$cols, cex=0.6, bty="n")

enter image description here