我已经使用下面的数据框通过plotly的plot_mapbox()创建了国家弦乐世界地图。尽管地图可以正常显示
Country<-c("United States","Canada","France","Italy","Turkey","United
States","Canada","France","Italy","Turkey")
Val<-c(50,67,89,567,9,50,67,89,567,9)
Name<-c('AD',"FGH","BGH","FGFG","EWRW",'ADy',"FGyH","BGyH","FGFyG","EyWRW")
Test<-data.frame(Country,Val,Name)
V11 <- aggregate(Val~Country,Test,sum)
library(plotly)
library(ggplot2)
library(dplyr)
WorldData <- map_data('world') %>% filter(region != "Antarctica") %>% fortify
colnames(WorldData)[5]<-"Country"
WorldData$Country <- gsub('USA', 'United States', WorldData$Country)
m2 <- data.frame(merge(V11,WorldData , by=c("Country"), all.x=T))
p <- m2 %>%
arrange(order) %>%
group_by(group) %>%
plot_mapbox(x = ~long, y = ~lat, color = ~Val, colors = c("#d7191c", "#2c7bb6"),
text = ~Country,hoverinfo = 'text', showlegend = FALSE) %>%
add_polygons(
line = list(width = 0.4)
) %>%layout(
margin = list(l = 10, r = 10, b = 10, t = 10, pad = 5),
plot_bgcolor = "#171b26",
paper_bgcolor = "#171b26",
clickmode = "event+select",
hovermode = "closest",
showlegend = FALSE,
autosize = TRUE,
mapbox = list(
accesstoken = mapbox_access_token,
bearing = 10,
center = list(lat = 36.16689, long = -76.22178),
pitch = 5,
zoom = 5,
style = "mapbox://styles/plotlymapbox/cjvppq1jl1ips1co3j12b9hex"
)
)
p
当我尝试使用text = paste("Country:",~Country,"Value:",~Val)