0

I'm using the rivers_lake_centerlines dataset from rnaturalearth to plot rivers on a map in R. The map is produced with ggmap. My workflow:

# download and save river drainages as an object
rivers10 <- ne_download(scale = 10, type = 'rivers_lake_centerlines', category = 'physical')

# set my coordinate extents for plotting with `ggmap`
myLocation <- c(-109.5, 37, -103, 31.5)

# get the map I want to use for plotting river drainages with `ggmap` function `getmap`
# save as an object
map1 <- get_map(location=myLocation, crop = F,
                color="bw",
                maptype="terrain",
                source="google",
                zoom=8)

sitemap <- ggmap(map1, extent = 'device') # use the BW terrain option
rivers_df <- fortify(rivers10) # make river data spatial for ggplot

# plot map with river data
 sitemap +
  labs(x = "Longitude", y = "Latitude") +
  
  geom_path(
    data = rivers_df,
    aes(long, lat, fill = NULL),
    color = "#2A788EFF",
    alpha = 0.5)

Plot produced:

enter image description here

My question: Why am I getting the rivers plotted as oddly shaped straight lines?

  • You probably have a few points out of order in the data. `geom_path()` connects the points in the order in which they appear in the data. You can either get different (correct) source data, find some way to properly sort the data, or just filter out those few points by enforcing a maximum distance to adjacent points or something similar. It looks like it's only a small number of bad points so removing them might be the best option that has minimal effect on the final output. – Dan Adams Mar 15 '22 at 00:09
  • Use `st_as_sf` to make rivers an sf object, and follow this post: https://stackoverflow.com/a/50844502/7547327 `ggmap` is difficult to work with. – mrhellmann Mar 15 '22 at 01:13

0 Answers0