2016-10-25 58 views
1

可以說我有兩個數據集,countriescities[R結合等值線與情節繪製座標

set.seed(42) 

countries <- data.frame(country = c("DEU", "FRA", "ITA", "POL"), 
         intensity = abs(rnorm(4))) 

cities <- data.frame(city = c("Berlin", "Paris", "Roma", "Warszawa"), 
        longitude = c(13.408333, 2.351667, 12.483333, 21.033333), 
        latitude = c(52.518611, 48.856667, 41.883333, 52.216667)) 

countries描述強度的國家一級數據集。 cities是一個包含座標的數據集。到目前爲止,我已經使用rworldmap繪製的強度:

library(rworldmap) 

map <- joinCountryData2Map(countries, joinCode = "ISO3", nameJoinColumn = "country") 

mapCountryData(map, nameColumnToPlot = "intensity", mapRegion = "Europe") 

我如何結合國家一級數據的地區分佈圖與根據城市數據組點的重疊?

回答

1

如果我理解正確的話,你可以加點使用points地圖:

map <- joinCountryData2Map(countries, joinCode = "ISO3", nameJoinColumn = "country") 
mapCountryData(map, nameColumnToPlot = "intensity", mapRegion = "Europe") 
points(cities$longitude, cities$latitude, col = "black", cex = 1.5) 
+0

很好,謝謝。我以爲我已經嘗試過,但顯然我錯過了一些東西。 – roming