I tried to modify the hoverinfo using style function of plotly and end up displaying the entire column information on every hover point.
I tried to use style function using <\n>, “br”, “br /” and tooltip. The problem does not exist with ggplot objects converted to plotly objects.
library(tidyverse)
library(plotly)
library(choroplethr)
library(choroplethrZip)
trips$region<- as.character(trips$zip)
trips$value<- as.numeric(trips$AVG_COST_PER_MILE)
title <- paste("Average Cost Per Mile ")
choropleths<- zip_choropleth(trips,title = title, state_zoom =
“delaware”)
mytext=paste(“Cost per Mile =”, trips$AVG_COST_PER_MILE, "
Trip Count
= “, trips$Trip_count, "
Cityname”,trips$CITY)
p<- ggplotly(choropleths)
style( p, text=mytext, hoverinfo = “text”)
I want to see hover-point display the appropriate information on a right point.
Sample Data :
trips<- trips<-structure(list(TIME = c(10L, 10L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 10L), zip = c(19700L, 19711L, 19720L, 19730L, 19731L, 19732L,
19735L, 19801L, 19814L, 19901L), AVG_COST_PER_MILE = c(3.33,
2.63, 2.05, 2.85, 2.98, 5.32, 3.37, 2.57, 3.5, 1.95), Trip_count = c(2L,
1L, 7L, 5L, 3L, 1L, 10L, 0L, 1L, 0L), CITY = structure(c(3L,
6L, 5L, 1L, 8L, 9L, 2L, 10L, 7L, 4L), .Label = c(" Odessa", " Winterthur",
"Delaware City", "Dover", "New Castle", "Newark", "Newport",
"Port Penn", "Rockland", "Wilmington"), class = "factor"), latitude =
c(39.57032, 39.70056, 39.66922, 39.45648, 39.51816, 39.7945,
39.7944, 39.73856, 39.71363, 39.16426), longitude = c(-75.59066, -75.7431,
-75.59003, -75.65976, -75.57656, -75.57433, -75.5976, -75.54833, -75.59628,
-75.51163)), class = "data.frame", row.names = c(NA, -10L))