0
votes

I've been trying to plot a rivers system over a ggmap and hitting a bunch of walls. Hopefully there is a good solution.

Here is where I'm getting the rivers data: https://data.review.fao.org/map/catalog/srv/api/records/6a53d768-1e20-46ea-92a8-c4040286057d

Loading in:

basemap <- get_stamenmap(bbox = c(left = 149.5, bottom = -35.9, right = 151.5, top = -32.5),
 zoom = 3, maptype = 'terrain-background')

rr <- st_read("rivers_australia_37252/rivers_australia_37252.shp")
 box = c(xmin = 145, ymin = -37, xmax = 155, ymax = -30)
rivers <- st_crop(rr, box)

class(rivers)
[1] "sf"         "data.frame"

Plotting and problem code

ggmap(basemap) +
 geom_sf(data=rivers, inherit.aes = FALSE)
# Error in st_cast.POINT(x[[1]], to, ...) : cannot create MULTILINESTRING from POINT


ggmap(basemap) +
 geom_sf(data=rivers, aes(geometry), inherit.aes = FALSE)
# Error in is.finite(x) : default method not implemented for type 'list'

I then tried unlist() and it came up with a fortify error. Any suggestions of how to transform the data or what to add in the geom_sf() code would be appreciated. Thanks!

This runs fine for me (except in your second ggmap call, I specified aes(geometry = geometry). What R and package versions are you using?walter
Sadly the aes(geometry = geometry) still gives me the same multilinestring error. I am running R 4.2.1, ggplot2 3.3.6 and ggmap 3.0.0. Which versions are you running? I can try changing to that.mirabug
I'm on R 4.2.1, same versions of ggplot2 and ggmap as you, and sf 1.0.8walter
Could you run sessionInfo() after running your code, and add the output into your question?walter