-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add coord_bc()
function to specify ggplot2 bounding box in lat/long
#65
Comments
Hi @schckngs, this is a good question! You can set it using lat/long if you specify library(sf)
#> Linking to GEOS 3.8.1, GDAL 3.1.1, PROJ 6.3.1
library(bcmaps)
library(ggplot2)
ggplot() +
geom_sf(data = bc_bound(), fill = "grey", colour = "black") +
coord_sf(xlim = c(-132, -129), ylim = c(51.5, 54), crs = st_crs(4326)) Created on 2020-07-16 by the reprex package (v0.3.0) I think there may be space in library(sf)
library(bcmaps)
library(ggplot2)
coord_bc <- function(xlim, ylim, crs = sf::st_crs(4326), ...) {
box <- sf::st_bbox(c(xmin = min(xlim), xmax = max(xlim),
ymin = min(ylim), ymax = max(ylim)),
crs = crs)
box <- sf::st_bbox(
sf::st_transform(sf::st_as_sfc(box), sf::st_crs(3005))
)
ggplot2::coord_sf(xlim = box[c("xmin", "xmax")],
ylim = box[c("ymin", "ymax")],
...)
}
ggplot() +
geom_sf(data = bc_bound(), fill = "grey", colour = "black") +
coord_bc(xlim = c(-132, -129), ylim = c(51.5, 54)) Created on 2020-07-16 by the reprex package (v0.3.0) Thoughts @stephhazlitt @boshek @gcperk? |
Thank you! This is great. |
coord_bc()
function to specify ggplot2 bounding box in lat/long
Using this a little I am seeing that I am really choosing one of the features (or collection of features) to defining this window. Having to find the bounding box of that feature and then manually extract the limits is a little clunky. What if
|
I think that would be a different (but welcome) function @boshek - I think it's quite common to just want your plot zoomed in on a particular area by specifying lat/long |
Would it make sense to have |
Possibly, though a couple of things:
|
I think you are definitely right that we don't want to change the syntax or behaviour of |
Bumping this issue, as I came across another user looking for the feature. |
Just coming back to this - I realized that the original use case defined by @schckngs can be achieved by specifying xlim and ylim in lat/long, and setting the library(sf)
library(bcmaps)
library(ggplot2)
ggplot() +
geom_sf(data = bc_bound(), fill = "grey", colour = "black") +
coord_sf(xlim = c(-132, -129), ylim = c(51.5, 54), default_crs = 4326) Created on 2023-11-20 with reprex v2.0.2 |
So is it worth implementing @boshek's suggestion to specify an sf[c] object or bbox? It's a more general problem than just B.C. though |
Hey @ateucher and all - it has been a while since I looked at this page. Thanks for keeping the conversation going! |
Hi,
This is a great package and I'm starting to use it more often.
I'm posting here to get input on mapping sub-regions of BC using ggplot with the bc_bound_hres().
Currently for quickly mapping I convert the lat/lon of my study area to UTM and enter in coord_sf(), e.g.:
ggplot() + geom_sf(bc_bound_hres(), fill = "grey", colour = "black") + coord_sf(xlim = c(600000, 800000), ylim = c(745000, 1000000))
If it is possible to set limits in lat/lon it would be faster and more intuitive, but I haven't figured out how best to do that yet. Pardon if there is an obvious way of doing this.
Cheers!
The text was updated successfully, but these errors were encountered: