0

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.

1 Answers1

1

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().

I_O
  • 4,983
  • 2
  • 2
  • 15
  • Hi, thank you for answering my question! Could you help me understand your solution better? Do you mean I need, for example, to change the latitude and longitude of each Chinese Province, making it close to the USA. And then use the same code (I used above) to draw the plot? And could you help explain how to use st_transform in my situation (i.e., I need to change the size of Alaska)? – Liman_1 Wang Jan 18 '23 at 00:16
  • You need to change each feature you want to shift. If you have one feature per province, you can change them separately or combine them with `st_union` and then shift the whole thing. If you want to plot the world (?) but shift only China, you need to extract that part into a separate `sf`. `transform`ation applies to all `sf` you plot on your map (unless you want a map medley). All these are basic operations covered in the `sf` package documentation. – I_O Jan 18 '23 at 07:07
  • 1
    Hi I_O, thank you very much for your help. I have figured it out! I changed the multipolygon data of Alaska and Hawaii, using your code "st_geometry() + c(.1, -.1)", but with a minor revision. For Alaska, I used "alaska$geometry1 <- alaska %>% st_geometry() * 0.4 + c(-53, 2)", for Hawaii, I used "hawaii$geometry1 <- hawaii %>% st_geometry() + c(55, 5)". I also relocate China by "china_select_current$geometry1 <- china_select_current %>% st_geometry() + c(-135, 0)" Then I rbind all the dataset . – Liman_1 Wang Jan 22 '23 at 17:26