2017-09-30 10 views
1

を参照するには:Mousehover私は世界のマップを作成しています、その名前

library(leaflet) 
library(rnaturalearth) 
countries <- rnaturalearth::countries110 
mymap <- leaflet(countries) 
mymap %>% addPolygons(stroke = FALSE, smoothFactor = 0.2, fillOpacity = 1) 

は、その名前を参照するか、そのを確認するために、任意の国をクリックしていずれかの国の上にマウスを移動するか、それが可能です名?

ありがとうございます!

答えて

2

あるいは、さらに簡単:限り、ラベルのデータが~表記は魔法のように動作プロットされるデータフレームの一部であるとして

library(leaflet) 
library(rnaturalearth) 

countries <- rnaturalearth::countries110 
mymap <- leaflet(countries) 
mymap %>% addPolygons(stroke = FALSE, smoothFactor = 0.2, 
         fillOpacity = 1, label = ~name) 

1

解決策を見つけました。 まず、ライブラリ "htmltools"を使用してラベルのリストを作成してください 次にlabel =の下に貼り付けます。だから、最終的なコードは次のとおりです。

library(leaflet) 
library(rnaturalearth) 
library(htmltools) 

countries <- rnaturalearth::countries110 
mymap <- leaflet(countries) 
labs <- as.list(countries$name) 
mymap %>% addPolygons(stroke = FALSE, smoothFactor = 0.2, 
         fillOpacity = 1, label = lapply(labs, HTML)) 
関連する問題