Description
Due to this SO question, I discovered that while geom_sf
does pass aesthetics through to the appropriate layer (here to plot linestrings as paths), e.g. size
, it doesn't pass parameters like lineend
, linemitre
, linejoin
, and arrow
, which are parameters of geom_path
, not aesthetics like size
or linetype
. In this case, this makes getting rid of the gaps in this plot harder:
# Reprex from SO question linked above
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.1.3, proj.4 4.9.3
library(osmdata)
#> Data (c) OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright
library(ggplot2)
# define bounding box for osm data
my_bbox <- matrix(
c(-0.2605616, -0.2605616,
-0.2004485, -0.2004485,
-0.2605616, 51.4689943,
51.4288980, 51.4288980,
51.4689943, 51.4689943),
ncol = 2
)
bbox_sf <- st_geometry(st_polygon(x = list(my_bbox)))
st_crs(bbox_sf) <- 4326
# get osm road data for bounding box
osm_roads_secondary_sf <-
opq(bbox = st_bbox(bbox_sf)) %>%
add_osm_feature(key = 'highway', value = 'secondary') %>%
osmdata_sf()
ggplot(osm_roads_secondary_sf$osm_lines) +
geom_sf(size = 4, lineend = "round")
#> Warning: Ignoring unknown parameters: lineend
According to ?geom_sf
, these parameters get passed through ...
to the paired geom/stat or layer
, though that function doesn't have parameters for everything or dots—I'm assuming they're passed to its params
parameter. The problem here seems to be that the paired stat here is stat_sf
, which does not have the specified parameters and is not passing them along further.
Ultimately this behavior is a product of the fact that geom_sf
dispatches to so many...geoms? As a sort of meta-geom it's more strongly opinionated than the rest of the API, making it hard to, say, use sf points as locations for geom_text
without pulling out the coordinates. Guidance in the docs on what sf geometry type dispatches to what geom (?) (and whether there's a way to override that dispatching) and thus what parameters can be passed would be welcome.