我试图使用plotly的样式功能修改hoverinfo,最终在每个悬停点上显示整个列信息。
我尝试使用<\ n>,“ br”,“ br /”和工具提示使用样式功能。 ggplot对象转换为plotly对象时不存在此问题。
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, "<br> Trip Count
= ", trips$Trip_count, "<br> Cityname",trips$CITY)
p<- ggplotly(choropleths)
style( p, text=mytext, hoverinfo = "text")
我想看到悬停点在正确的点上显示适当的信息。
样本数据:
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))