Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Plotly Scatter Plots on Maps - Hover Function - R

Hi, the R code on the Plotly website for scatter plots on maps is incorrect. This code does not reproduce the hover text shown on the map. Only the points are plotted on the map, with no hover functionality. Is there a workaround for this, or better code maybe to achieve the same outcome?

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 = “
”),
color = ~cnt, symbol = I(“square”), size = I(8), hoverinfo = “text”
) %>%
colorbar(title = “Incoming flights
February 2011”) %>%
layout(
title = ‘Most trafficked US airports
(Hover for airport)’, geo = g
)

Hey @neel123

It looks like there may be an issue with hoverinfo and plot_geo. I’ve opened an issue here https://github.com/ropensci/plotly/issues/11271

also referenced in this thread Hover text not working