1

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

  • I get an interactive plot in the output when I put your code into R Markdown and knit to an HTML document; is that what you are doing? – aosmith May 30 '18 at 15:00
  • @aosmith I am doing that yes. – Scott Warren May 30 '18 at 15:29
  • Are your packages up to date and such? I can't reproduce the problem using R 3.4.4 on Windows; I get an interactive graph in the output HTML. I did have to get **ggiraph** and its support packages updated to current CRAN versions before I could test. Maybe add some session info details to your question? – aosmith May 30 '18 at 15:39
  • @aosmith updated the question for more clarity; also everything is up to date as it's a fresh install on a new (to me and R) computer – Scott Warren May 30 '18 at 15:47
  • 1
    It's possible that this is an issue with R 3.5 and RStudio, as I've seen a few of those being discussed around the internet. See, e.g., [this github issue](https://github.com/rstudio/rstudio/issues/2774). Maybe try [RStudio 1.1.455](https://github.com/rstudio/rmarkdown/issues/1353#issuecomment-392814747) (not released yet). – aosmith May 30 '18 at 16:16
  • @aosmith it may be, I'll have an investigate and report back. Thanks for your suggestions – Scott Warren May 30 '18 at 16:22

0 Answers0