2017-06-05 3 views
1

Hallo, ich möchte nur eine Legende zu dieser Karte hinzuzufügen, die die Fruchtbarkeit der jungen Frauen von Abteilungen in Frankreich repräsentiert: enter image description hereR fügen Sie eine Legende auf eine Frankreich-Karte

Mit diesem Code:

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) 

Ich weiß nicht, wie ich diese Legende hinzufügen soll.

+0

Hier finden Sie aktuelle Funktion 'legend'. – Lamia

+0

Legende (LON, LAT, legende = Klassen, fill = fr $ cols) ?? – PiecesOfMagics

Antwort

1


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

+0

Danke, es funktioniert;) Ich habe auch eine andere Lösung gefunden. – PiecesOfMagics

+0

teilen (als Antwort) – yeedle

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

enter image description here

Verwandte Themen