Please have a look at the reprex at the end of this post. I should say that because of an issue with the ne_download function, the reprex requires the development version of rnaturalearth. See
R+natural earth: download bounding box fails
The code below works, but it seems to me that, with respect to the past, the equatorial line and all the latitude line have disappeared. Is there any way to bring them back? Thanks!
PS: are the warnings that the code generate now anything I should be worried about?
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
library(rnaturalearth)
library(sf)
#> Linking to GEOS 3.9.0, GDAL 3.2.2, PROJ 7.2.1; sf_use_s2() is TRUE
ww_ini <- ne_countries(scale = "medium",
type = 'map_units',
returnclass = "sf")
bb <- ne_download(type = "wgs84_bounding_box", category = "physical",
returnclass = "sf")
#> Warning: OGR support is provided by the sf and terra packages among others
#> Warning: OGR support is provided by the sf and terra packages among others
#> Warning: OGR support is provided by the sf and terra packages among others
#> Warning: OGR support is provided by the sf and terra packages among others
#> Warning: OGR support is provided by the sf and terra packages among others
#> Warning: OGR support is provided by the sf and terra packages among others
#> OGR data source with driver: ESRI Shapefile
#> Source: "/tmp/Rtmp3wWhXe", layer: "ne_110m_wgs84_bounding_box"
#> with 1 features
#> It has 2 fields
gpl2 <- ggplot(data = ww_ini) +
geom_sf( col = "black", lwd = 0.3 )+
xlab(NULL) + ylab(NULL) +
ggtitle("Test title")+
geom_sf(data = bb, col = "grey", fill = "transparent") +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = 'white'),
panel.grid.major = element_line(colour = "grey"),
legend.position="top",
plot.title = element_text(lineheight=.8, size=24, face="bold",
vjust=1),
legend.text = element_text(vjust=.4,lineheight=1,size = 14),
legend.title = element_text(vjust=1,lineheight=1, size=14,
face="bold" ))+
coord_sf( crs = "+proj=eqearth +wktext")
gpl2
sessionInfo()
#> R version 4.2.2 (2022-10-31)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 11 (bullseye)
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#>
#> locale:
#> [1] LC_CTYPE=en_GB.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_GB.UTF-8 LC_COLLATE=en_GB.UTF-8
#> [5] LC_MONETARY=en_GB.UTF-8 LC_MESSAGES=en_GB.UTF-8
#> [7] LC_PAPER=en_GB.UTF-8 LC_NAME=C
#> [9] LC_ADDRESS=C LC_TELEPHONE=C
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] sf_1.0-9 rnaturalearth_0.3.0 ggplot2_3.4.0
#> [4] dplyr_1.0.10
#>
#> loaded via a namespace (and not attached):
#> [1] styler_1.8.0 tidyselect_1.2.0 xfun_0.35
#> [4] purrr_1.0.0 lattice_0.20-45 colorspace_2.0-3
#> [7] vctrs_0.5.1 generics_0.1.3 htmltools_0.5.3
#> [10] yaml_2.3.6 utf8_1.2.2 rlang_1.0.6
#> [13] R.oo_1.25.0 e1071_1.7-12 pillar_1.8.1
#> [16] glue_1.6.2 withr_2.5.0 DBI_1.1.3
#> [19] R.utils_2.12.1 sp_1.5-1 R.cache_0.16.0
#> [22] lifecycle_1.0.3 stringr_1.5.0 munsell_0.5.0
#> [25] gtable_0.3.1 R.methodsS3_1.8.2 evaluate_0.18
#> [28] knitr_1.41 fastmap_1.1.0 class_7.3-20
#> [31] fansi_1.0.3 highr_0.9 Rcpp_1.0.9
#> [34] KernSmooth_2.23-20 scales_1.2.1 classInt_0.4-8
#> [37] jsonlite_1.8.4 farver_2.1.1 fs_1.5.2
#> [40] digest_0.6.30 stringi_1.7.8 grid_4.2.2
#> [43] rgdal_1.6-2 cli_3.4.1 tools_4.2.2
#> [46] magrittr_2.0.3 proxy_0.4-27 tibble_3.1.8
#> [49] pkgconfig_2.0.3 reprex_2.0.2 assertthat_0.2.1
#> [52] rmarkdown_2.17 httr_1.4.4 R6_2.5.1
#> [55] units_0.8-1 rnaturalearthdata_0.1.0 compiler_4.2.2
Created on 2023-01-05 with reprex v2.0.2
The bounding box is present on your plot as the outline of the map. We can see this if we specifically colour it red. If you are looking for a rectangle drawn around the whole plot then use the colour
argument of panel.background
inside theme
(shown below)
I'm not sure what's going on with your equatorial line and latitude lines, since these show up as expected on my machine with the following code:
ggplot(data = ww_ini) +
geom_sf( col = "black", lwd = 0.3 )+
xlab(NULL) + ylab(NULL) +
ggtitle("Test title")+
geom_sf(data = bb, col = "red", fill = "transparent") +
theme(plot.background = element_rect(fill = "white"),
panel.background = element_rect(fill = 'white', colour = 'black'),
panel.grid.major = element_line(colour = "grey"),
legend.position="top",
plot.title = element_text(lineheight=.8, size=24, face="bold",
vjust=1),
legend.text = element_text(vjust=.4,lineheight=1,size = 14),
legend.title = element_text(vjust=1,lineheight=1, size=14,
face="bold" ))+
coord_sf( crs = "+proj=eqearth +wktext")