Unnecessary coord_sf() calls in plotting examples?
In lesson 6 there is a statement about the need to call coord_sf() when plotting sf objects with ggplot:
https://github.com/datacarpentry/r-raster-vector-geospatial/blob/16a9d65327090c4489fcb4f9e4460db799ad7097/_episodes_rmd/06-vector-open-shapefile-in-r.Rmd#L141
However when you call coord_sf() without any arguments, it just pulls the CRS from the first layer with a coordinate system and transforms the other layers, and this is actually done by default if you use geom_sf() (see the documentation here: https://ggplot2.tidyverse.org/reference/ggsf.html). The only time I've needed to use coord_sf() was when I wanted to customize the coordinate display in some more complex way.
I suggest removing these calls to coord_sf() from the example plots in lesson 6 and the later lessons to keep the code clean and potentially to draw attention to more complex situations where it is actually necessary (though I don't think it's ever called with an argument in any of the lessons?).
If there's agreement and I'm not missing something, I can submit a pull request updating the examples using geom_sf() while making sure they still plot correctly.
I agree that these lines are probably unnecessary but my read is that the calls to coord_sf were added to ease the transition from raster plotting using coord_quickmap in lesson 2. See #240, #242 and 9d5314578673e6cfefe5fe777bf653e5796ab560. Would this change make that transition more difficult? Is there a way to similarly streamline the raster plotting?
That's a great point. I doubt it's possible to avoid calling coord_quickmap or a similar function since raster data isn't necessarily spatial and thus geom_raster or similar isn't going to make any guesses about how it should be plotted (i.e., with an associated projection) the way geom_sf would with shapefile data.
I would still argue that it's better to leave out the unnecessary line (and I would say it's incorrect to say that you need to use coord_sf as the lesson states), but I haven't taught these lessons so I can't say if learners would get confused by the lack of an explicit definition of the coordinate system.
I agree with @kenkellner here, coord_sf() is certainly superfluous, and should probably be removed entirely. I don't see how it eases the transition, it's very rare to use coord_ in general with ggplot2, plotting raster data is an oddity in that respect, and if anything, I think not using coord_sf() would be less confusing in comparison to normal ggplot2 use, e.g. as they would have learned in the Intro to R for Geospatial lesson.
While I agree that the placement of coord_sf() in this particular lesson can be confusing and is poorly placed, I do believe that it is a useful tidbit to know for plotting raster data that may be stretched incorrectly during plotting. Perhaps the best course of action is to remove this line from the actual code and add it to a Data Tip section within this episode? It could easily be linked to the coord_quickmap() that was discussed in the Plot Raster Data episode.