I'm a map newbie in R and am at my wits end trying to figure this out. I used ggmap() to create a map of the U.S. I then overlaid some cities with their latitude and longitudes using geom_point().
When the user does a hover or click, I am able to retrieve the coordinates - however, these coordinates are x-y, that range from 0 to 1.
I'm trying to ascertain that city was clicked by computing the distance between the point of click/hover (x-y) to the city.
How do I covert the latitude / longitude data into x-y coordinates?
Any help is greatly appreciated!
Here is the code: Inside the renderPlot() function, I have the following running:
usa.map = get_map(location = 'United States',zoom = 4, color = 'bw')
g <- ggmap(usa.map) +
geom_point(data = annual_data, mapping = aes(x=LONGITUDE, y=LATITUDE, colour = delay.class), size=3) +
scale_colour_gradient(low = "white", high = "red")
In the renderPrint() function, I'm catching a hover event:
output$hover_info <- renderPrint({
if(!is.null(input$plot_hover)){
hover=input$plot_hover
}
})
The input$plot_hover object has fields X and Y, that range from 0 to 1 i.e. in the plotting process, the latitude and longitude values have been rasterized (I'm not sure, but that's what I think).