0

I'm al little confused on how to make my points show information when they are being hovered over. currently this code makes the value that I want to show come up automatically on the map, not when you hover over the points. Since there are 10,000+ data points, it shows a mess of values all over the place. I know plotly is a library to make this sort of thing happen but I tried a couple of small adjustments to the code with the library and it all failed. the code is pasted below as well as a link to an image of what the code produces. PLEASE HELP!

library(ggplot2)

library(ggmap)

library(maps)

library(mapdata)

library(geosphere)

library(zoom)

library(ggrepel)

library(plotly)



states <- map_data("state")
regionofInterest<- subset(states, region %in% c("california", "arizona", "new mexico", "texas", "oklahoma","kansas", "missouri", "arkansas", "louisiana", "illinois", "mississippi","indiana", "kentucky", "tennessee", "alabama", "ohio", "west virginia", "virginia", "north carolina", "south carolina", "georgia", "pennsylvania", "delaware", "maryland", "new jersey"))



ggplot(data = regionofInterest) +
 geom_polygon(aes(x = long, y = lat, group = group), fill = "#efede1", color = "black") +

 geom_curve(data=dataset, aes(x = dataset$LNG_BASE, y = dataset$LAT_BASE, xend = dataset$LNG, yend = dataset$LAT), col = "#b29e7d", size = 1, curvature = .2) + 

 geom_point(data=dataset, aes(x = dataset$LNG, y = dataset$LAT), col = "red") + 

 geom_text_repel(data=dataset, aes(x = dataset$LNG, y = dataset$LAT, label = round(dataset$DISTANCE)), col = "black", size = 2, segment.color = NA) + 

theme(panel.background = element_rect(fill="white"), 
 axis.line = element_blank(),
 axis.text.x = element_blank(),
 axis.text.y = element_blank(),
 axis.ticks = element_blank(),
 axis.title.x = element_blank(),
 axis.title.y = element_blank()
 )

IMAGE OF CODE OUTPUT

S.Ahmed
  • 1
  • 1
  • Welcoem to SO. I get _"Error in fortify(data) : object 'dataset' not found"_ when I run your code. Please provide a [minimal reproducible example](https://cran.r-project.org/web/packages/reprex/README.html#what-is-a-reprex) as asked by the R tag (hover over it). Thanks. – lukeA Jun 29 '17 at 17:11
  • hmm so unfortunately I'm using a dataset that is restricted.. so I don't really know how to get the code running, because I have no actual dataset to provide. I was hoping that the details of the code would help simulate a solution – S.Ahmed Jun 29 '17 at 17:42
  • There are many build-in data sets and also ways to create enough dummy data to recreate the problem. Check out [this thread](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610), too. – lukeA Jun 29 '17 at 21:29

0 Answers0