I found the following example for plotting a map with Canadian cities: https://plot.ly/ggplot2/maps/
The R code reads as follows:
library(plotly)
Sys.setenv("plotly_username"="XXXXXXXXX")
Sys.setenv("plotly_api_key"="YYYYYYYYY")
data(canada.cities, package="maps")
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions="canada", name="borders") +
coord_equal() +
geom_point(aes(text=name, size=pop), colour="red", alpha=1/2, name="cities")
ggplotly()
I would like to modify the example in a way that the name of the city shows up when hovering with the mouse over the relevant point in the map.
How would I need to modify the above example to implement this?
This ended up being a bug, so thanks for reporting! I just issued a fix here so try re-installing ( devtools::install_github("ropensci/plotly")
) and re-running:
data(canada.cities, package="maps")
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions="canada", name="borders") +
coord_equal() +
geom_point(aes(text=name, size=pop), colour="red", alpha=1/2, name="cities")
ggplotly()
Here's a screenshot, with the custom hover text!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.