0
votes

I want to add hover text to this map (from ~IntZoneName) but just can't find a way. Am I correct to be using scatter? I'm using spatial files which I've joined with a dataframe and then using Plotly to make graph interactive. Currently hover is just displaying data from ~CrudeRate7DayPositive.

plot_ly(map_x,
        type = "scatter",
        color = ~CrudeRate7DayPositive,
        colors = cols,
        text = ~IntZoneName, 
        hoverinfo = "text",
        alpha = 0.8) %>% 
        layout(title = "Crude Rates") 

Screen shot of map

1

1 Answers

0
votes

I gave up on plotly and went with ggiraph which did everything I wanted

gg <- ggplot(map_x) +
  geom_sf_interactive(aes(fill = CrudeRate7DayPositive, 
                          tooltip = c(paste0(IntZoneName, "\n",CrudeRate7DayPositive,  " cases per 100,000 \n (7 Day Crude Rate)")),  
                          data_id = IntZoneName)) +
  scale_fill_brewer(palette = "Purples") +
  theme_void()
x <- girafe(ggobj = gg)
x <- girafe_options(x,
                    opts_zoom(min = 0.7, max = 2) )
if( interactive() ) print(x)