【问题标题】:R add a legend to a france mapR向法国地图添加图例
【发布时间】:2017-06-05 21:55:52
【问题描述】:

您好,我只想在这张地图上添加一个图例,代表法国各部门年轻女性的生育能力:

使用此代码:

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)

我不知道如何添加那个图例。

【问题讨论】:

  • 看看函数legend
  • legend(LON,LAT, legend=classes,fill=fr$cols)??

标签: r maps legend


【解决方案1】:


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

【讨论】:

  • 分享(作为答案)
【解决方案2】:
locator(n=1)
legend(-6.780717,45.01717,legend=classes,
fill=fr$cols, cex=0.6, bty="n")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-24
    • 1970-01-01
    • 2013-06-13
    • 2019-03-05
    • 1970-01-01
    • 2021-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多