0

I am using this code for Ecuador

library(rnaturalearth)
install.packages("rnaturalearthhires", repos = "http://packages.ropensci.org", type = "source")
library(rnaturalearthhires)

ecuador<-ne_states(country = "ecuador", returnclass = "sf")

ggplot(data = ecuador)+geom_sf()

I get this graph:

I really don't need the longitude and latitude, but I would like to get Galapagos Islands Closer.

So far I tried to change the longitude from almost -90 to -82, but that isn't working.

What can I do?

enter image description here

Thanks in advance.

EDIT: I got the code from here and just adapt it to my needs: How to obtain maps with regions and subregions

Jorge Paredes
  • 996
  • 7
  • 13
  • 1
    You may need to use `devtools::install_github("ropensci/rnaturalearthhires")` to install `rnaturalearthhires`. The code in the question did not work for me. – Peter Apr 08 '21 at 16:53
  • 1
    Not sure if this would work for you or not, but you could consider faceting the two figures. As far as I am aware ggplot does not let you break axes, which I think is what you are hoping to do. – melmo Apr 08 '21 at 16:57
  • @Peter that's odd, because the code you put didn't worked for me so I used the one that's my post. – Jorge Paredes Apr 08 '21 at 17:03
  • @melmo, yes I've tried that. But still didn't work. – Jorge Paredes Apr 08 '21 at 17:04

1 Answers1

2

You could try this using tmap

library(rnaturalearth)
library(rnaturalearthhires)
library(tmap)
library(sf)

simple feature data for Ecuador

ecuador <- ne_states(country = "ecuador", returnclass = "sf")

set bounding box coordinates for Ecuador and Galápagos Islands

bbox_ec <- st_bbox(c(xmin = -85, xmax = -75, ymax = 2, ymin = -5.5), crs = st_crs(4326))
bbox_gi <- st_bbox(c(xmin = -92, xmax = -89, ymax = 2, ymin = -2), crs = st_crs(4326))

create map objects

map_gi <- 
  tm_shape(ecuador, bbox = bbox_gi)+
  tm_polygons()+
  tm_layout(frame = "white")+
  tm_scale_bar()

map_ec <-
  tm_shape(ecuador, bbox = bbox_ec)+
  tm_polygons()+
  tm_scale_bar()

combine maps and print

map_ec
print(map_gi, vp = grid::viewport(0.2, 0.65, width = 0.5, height = 0.5))

some issues:

Setting the bounding box and position of the Galápagos Islands inset is by eye with trial and error; so this could most likely be improved.

The scale of the plots is bound to be different. There may be a way to make the scale equal, I've taken the easy way out by including the tmap scale for each plot.

Created on 2021-04-08 by the reprex package (v1.0.0)

Peter
  • 11,500
  • 5
  • 21
  • 31