Linking points from two separate ggplots together with lines

Viewed 57

I have two figures, one phylogenetic tree generated with ggtree, and a map plot generated with ggmap. The two figures have points that I want to link with a line between the plots, like so: enter image description here

However, all the previously asked questions I could find only covered linking points within the same plot, not across plots. Is there any way to do this?

Example code is here:

library(ggplot2)
library(ggmap)
library(ggtree)

tree <- rtree(5)

testdata <- structure(list(id = c("t1", "t3", "t5", "t4", "t2"), city = c("Oslo", 
"Drammen", "Bergen", "Kristiansand", "Trondheim"), lat = c(59.9138688, 
59.7440738, 60.3912628, 58.1599119, 63.4305149), lon = c(10.7522454, 
10.2044565, 5.3220544, 8.0182064, 10.3950528)), class = "data.frame", row.names = c(NA, 
-5L))

limits <- c(left = 3, bottom = 57, right = 32, top = 71.5)
norway_map <- get_stamenmap(bbox = limits, zoom = 6, maptype = "toner-lite")

ggtree(tree) %<+% testdata +
  geom_tippoint(aes(fill = city),
                pch = 21,
                size = 3) +
  theme(legend.position = "none") +
  ggmap(norway_map) +
  geom_point(data = testdata,
             aes(x = lon,
                 y = lat,
                 fill = city),
             pch = 21,
             size = 3) +
  theme(axis.text = element_blank(),
        axis.title = element_blank())

Unfortunately, the ggmap requires access to google API services. Other maps can also be used if preferred.

0 Answers
Related