我尝试在地图上的散点图在R poltly示例中,这是由plotly提供的。 https://plot.ly/r/scatter-plots-on-maps/
但是,当我复制代码并在rstudio中运行时,我无法使悬停功能正常工作。
library(plotly)
df <- read.csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_february_us_airport_traffic.csv')
# geo styling
g <- list(
scope = 'usa',
projection = list(type = 'albers usa'),
showland = TRUE,
landcolor = toRGB("gray95"),
subunitcolor = toRGB("gray85"),
countrycolor = toRGB("gray85"),
countrywidth = 0.5,
subunitwidth = 0.5
)
p <- plot_geo(df, lat = ~lat, lon = ~long) %>%
add_markers(
text = ~paste(airport, city, state, paste("Arrivals:", cnt), sep = "<br />"),
color = ~cnt, symbol = I("square"), size = I(8), hoverinfo = "text"
) %>%
colorbar(title = "Incoming flights<br />February 2011") %>%
layout(
title = 'Most trafficked US airports<br />(Hover for airport)', geo = g
)