Closed Jim89 closed 6 years ago
I have the very same problem. It would be wonderful to be able to combine ggmap and ggraph.
I absolutely want a way to combine ggraph with maps. My current sentiment is that I'll wait for the native sf support that will arrive in the next version of ggplot2 rather than get tangled in with another extension
@thomasp85 Thanks for the update. In a future version of ggraph, Could it be possible download online maps (gmaps or osm) as ggmap does?
This is unlikely to be part of ggraph as this is possibly out of scope. I'll wait with ruling this out completely until I start poking at the problem
@Jim89 @thomasp85 - Similar to this request (which I would be happy to submit separately), would be enabling network functionality atop Leaflet mapping.
Though I haven't tested it this RPub may be of interest here: https://rpubs.com/debasishb/298685
I was looking for a way to plot graphs with sf objects as nodes and couldn't find any solutions online. Since this issue is vaugely related to the plotting of spatial object, I thought I would post a solution here in case any one is interested.
# load packages
library(tidygraph)
library(ggplot2)
library(sf)
library(tibble)
# make data
nodes <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
edges <- tibble(from = 1:5, to = 6:10, type = letters[1:5])
# make centroids
ctr <- as.data.frame(as(st_geometry(st_centroid(nc)), "Spatial")@coords)
names(ctr) <- c("x", "y")
# make graph
g <- tbl_graph(nodes, edges)
# make plot
p <- ggraph(g, "manual", node.position = ctr) +
geom_sf(aes(fill = AREA), data = nodes) +
geom_edge_arc(aes(color = type))
# render plot
print(p)
I'm experiencing difficulty plotting a
ggraph
on top of aggmap
(metioned it on twitter).Here's the code I'm running to create the graph and the map:
If I then run:
I get the following error:
I feel like this could be due to the different names for the aesthetics in the two plots (
ggmap
uses lat/lon whereasggraph
insists onx
andy
) but I'm not convinced this is the case.Appreciate if you can take a look and make some suggestions. If there's any digging I can do on my end to help out, let me know! Thanks.
Here are the data necessary: