R地图包·给一些国家上色
生活随笔
收集整理的這篇文章主要介紹了
R地图包·给一些国家上色
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我需要在 R 地圖中繪制一些國家/地區,這些國家/地區是從數據集中提供的。國家必須根據排名值(1 到 5)著色,十六進制顏色值將自動分配。
library(maps) library(geosphere) library(magrittr)x <- map("world", plot=FALSE) paises <- (as.matrix(x$names))# Set of countries to be colored cntry <- c("Italy", "Portugal", "France", "Germany", "Spain") # Set of colors for the selected countries colset <- rainbow(length(cntry)) # Positions of the selected countries in the 'paises' vector poss <- lapply(cntry, function(x) grep(x, paises)) # Vector of colors to be passed to 'map' cols <- unlist(sapply(1:length(cntry), function(k) rep(colset[k], length(poss[[k]]))))# Plot all european countries in gray map("總結
以上是生活随笔為你收集整理的R地图包·给一些国家上色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: MSS代码解读-MmwDemo_mbox
- 下一篇: 【华为OD机试真题 JAVA】寻找身高相