我的问题是我正在尝试将自定义悬停文本添加到R中的绘图散点图框中。我发现我可以包含我想要的文本而不指定hoverinfo =' text'但是这给出了我不需要的输出(即经度和纬度,见下面的“地图”示例)。当我指定hoverinfo参数时,不会为所有点显示所需的文本。任何人都可以帮助我获取自定义悬停文本而无需工具提示中的其他信息吗?
library(plotly)
Sys.setenv('MAPBOX_TOKEN' = 'mapbox_token' )
Test <- data.frame(
Postcode = c(801, 820, 820, 822, 822),
Name_Organisation = c("Google", "Apple", "Microsoft","IBM","Rstudio"),
Org_Type = c("Training Provider","National Laboratory & Testing Facility","National Laboratory & Testing Facility","National Laboratory & Testing Facility", "Training Provider"),
State = c("NT","NT","NT","NT","NT"),
Latitude = c(-12.80081,-12.41066,-12.40957,-12.79939,-12.89939),
Longitude = c(130.9598,130.8604,130.8598,131.1294,131.1294),
RDOrgCap = c("Training Centres & Facilities","Testing facilities (public & private)","Testing facilities (public & private)","Testing facilities (public & private)","Testing facilities (public & private)")
)
basic <- list(method = "relayout",
args = list(list(mapbox.style = "basic")),
label = "Basic")
dark <- list(method = "relayout",
args = list(list(mapbox.style = "dark")),
label = "Dark")
satellite <- list(method = "relayout",
args = list(list(mapbox.style = "satellite")),
label = "Satellite")
#Hovertext works
Map <- plot_mapbox(data = Test, lon=~Longitude, lat = ~Latitude, type = "scattermapbox", mode = "markers",split = ~RDOrgCap,text = ~paste("State: ",State,"<br>","Region (Postcode): ",Postcode,"<br>", "Organisation Name: ",Name_Organisation, "<br>", "Organisation Type: ",Org_Type,sep = "" )) %>%
layout(mapbox = list(zoom = 3.5,
center = list(lat =-27 ,
lon =133)), legend = list(opacity= 1)
) %>%
layout(updatemenus = list(list(x = -0.01,
y = 1,buttons= list(basic,dark,satellite))))
Map
#Hovertext does not work
Map_1 <- plot_mapbox(data = Test, lon=~Longitude, lat = ~Latitude, type = "scattermapbox", mode = "markers", hoverinfo = 'text',split = ~RDOrgCap,text = ~paste("State: ",State,"<br>","Region (Postcode): ",Postcode,"<br>", "Organisation Name: ",Name_Organisation, "<br>", "Organisation Type: ",Org_Type,sep = "" )) %>%
layout(mapbox = list(zoom = 3.5,
center = list(lat =-27 ,
lon =133)), legend = list(opacity= 1)
) %>%
layout(updatemenus = list(list(x = -0.01,
y = 1,buttons= list(basic,dark,satellite))))
Map_1
请注意,我以前能够在3个月前没有任何问题的情况下做到这一点,但是我从那时起就更新了R和情节。不幸的是我不知道我之前使用的是什么版本,但我目前正在使用R版本3.4.1和版本4.7.1