-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmoving_country_names.R
27 lines (24 loc) · 1.38 KB
/
moving_country_names.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
library(rworldmap)
rm(list=ls())
df <- NULL
df$country <- c("El Salvador","Mexico","Panama", "Nicaragua", "Costa Rica", "Cuba", "Honduras", "Guatemala", "Venezuela")
df$code<-c("SLV", "MEX", "PAN", "NIC", "CRI", "CUB", "HON", "GTM", "VEN")
df$number<-c(100, 500, 200, 150, 300, 390, 140, 330, 60)
df<-as.data.frame(df)
sPDF <- joinCountryData2Map( df, joinCode = "ISO3", nameJoinColumn = "code")
mapCountryData(sPDF, nameColumnToPlot="number")
sPDFmyCountries <- sPDF[sPDF$NAME %in% df$country,]
mapCountryData(sPDFmyCountries, nameColumnToPlot="number", catMethod="fixedWidth", colourPalette="heat", borderCol="black", mapTitle = ("Made Up Number"))
text(sPDFmyCountries, labels="NAME")
rm(list=ls())
df <- NULL
df$country <- c("El Salvador","Mexico","Panama", "Nicaragua", "Costa Rica", "Cuba", "Honduras", "Guatemala", "Venezuela")
df$code<-c("SLV", "MEX", "PAN", "NIC", "CRI", "CUB", "HON", "GTM", "VEN")
df$number<-c(100, 500, 200, 150, 300, 390, 140, 330, 60)
df<-as.data.frame(df)
sPDF <- joinCountryData2Map( df, joinCode = "ISO3", nameJoinColumn = "code")
mapCountryData(sPDFmyCountries, nameColumnToPlot="number", catMethod="fixedWidth", colourPalette="heat", borderCol="black", mapTitle = ("Made Up Number"))
df2=as.data.frame(sPDFmyCountries)
df2$latOffset=4 #4 degree offset
df2$lonOffset=4
text(df2$LON+df2$latOffset, df2$LAT+df2$lonOffset, labels=df2$country)