I am trying to get an interactive plot whereby a mouse hover indicates the ID of each point so that it can be identified.
id <- c(1,2,3)
lat <- c(51,52,52)
lon <- c(0.1,1,-2)
coord <- data.frame(id, lat, lon)
library(ggiraph)
library(ggplot2)
UK <- map_data(map = 'world', region = c('UK', 'IRELAND'))
baseMap <- ggplot() +
coord_map() +
geom_path(data = UK, aes(x = long, y = lat, group = group))
finalMap <- baseMap +
geom_point_interactive(data = coord, aes(x = lon, y = lat, tooltip = id, size = 2))
ggiraph(ggobj = finalMap, width = 0.7)
This MWE outputs the basic plot that I'm after, however when I knit this (using RStudio) into a HTML document for reports I can only seem to get it to insert a static image without the tooltips.
Am I missing something obvious when it comes to actually implementing this in HTML?
Edit: I am using RStudio ver 1.1.453 on Windows with R version 3.5.0