I have a map of a region of canada that I created using ggplot and the sf package. At specific points on the map, I'd like to add a line leading to a callout of a graph using data from that location. I know how to do popups in leaflet, but this needs to be a document that works when I print out a hard copy. I also could do it in Illustrator, but coding it in would be best!
Any ideas?
Here is some example code
library(ggmap)
library(sf)
library(tidyverse)
# example point object
point.forMap = data.frame(lon=-111.19, lat=56.55, ID="1A3") %>%
st_as_sf(coords=c("lon", "lat")) %>%
st_set_crs(4326)
# Example data that I want to add as a graph
data.forGraph = data.frame(ID=rep("1A3", 30), xval=runif(30, min=5, max=20), yval=runif(30, min=0, max=20) )
# data for the background of the map
background_map = get_map(location=c(lon=-111.19, lat=56.5), zoom=8,maptype="satellite")
# plot the map
ggmap(background_map)+
geom_sf(data=point.forMap, inherit.aes = FALSE, size=8, color="red")
# plot the graph
ggplot(data=data.forGraph)+
geom_point(aes(x=xval, y=yval))
Now the question is, how do I get the graph to appear on the map somewhere near the point? Both the data.forGraph and point.forMap have an ID column that we can join the two dataframes on, but I'm not sure where to go from here.
