Liman_1 Wang
Liman_1 Wang

Reputation: 1

How to relocate the position on the map (ggplot/sf/geometry)

I am using R to draw a map of China and the USA. I would like to map the "holistic thinking" across these two countries. Could you help me with the followings?

  1. relocate these two countries? There is too much space between the two countries. I would like to narrow the space between the two countries and zoom the size of the two countries.
  2. smaller the size of "Alaska"? I think the size of Alaska is too big relative to the size of the USA.

This is my code.

holistic_10_plot1 <- st_read(" two_triad_current ") %>%
ggplot() +
geom_sf(aes(fill = holistic_10_province)) +
scale_fill_gradient(low = "lightblue", high = "darkblue") +
geom_sf_text(aes(label = province_current), color = "grey", family = "sans", angle = 0) +
theme_void() +
labs(title = "The number of holistic groups(10 focal groups) \n current states/provinces") +
theme(legend.position = "bottom", plot.title = element_text(hjust = 0.5), title = element_text(size = 14, face = "bold", color = "black")) +
guides(fill = guide_colorbar(title = "The number of the holistic groups", title.position = "top"))

This is the plot.

enter image description here

to relocate the positon of China or the USA to make them closer.

Upvotes: 0

Views: 326

Answers (1)

I_O
I_O

Reputation: 6911

You can shift an sf object simply by recalculating its geometry column like so:

library(sf)

## create example sf object "nc":
nc <- st_read(system.file("shape/nc.shp", package="sf"))

add another geometry column (or change it in place):

library(sf)

## shift geometry .1 degrees east and .1 degrees north:
nc$shifted_geometry <-  nc |> st_geometry() + c(.1, -.1)

plot original and shifted geometry:

nc |> st_geometry() |> plot()
nc$shifted_geometry |> plot(add = TRUE, border = 'red')

shifted geometry

Concerning the area, you could set an equal-area projection with st_transform().

Upvotes: 1

Related Questions