[英]How to relocate the position on the map (ggplot/sf/geometry)
I am using R to draw a map of China and the USA.
我用R画了一个中美map。 I would like to map the "holistic thinking" across these two countries.
我想 map 跨越这两个国家的“整体思维”。 Could you help me with the followings?
你能帮我解决以下问题吗?
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.
这是 plot。
enter image description here
在此处输入图像描述
to relocate the positon of China or the USA to make them closer.
重新定位中国或美国的位置,使它们更接近。
You can shift an sf object simply by recalculating its geometry column like so:
您可以简单地通过重新计算其几何列来移动sf object,如下所示:
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:
plot 原始几何和移位几何:
nc |> st_geometry() |> plot()
nc$shifted_geometry |> plot(add = TRUE, border = 'red')
Concerning the area, you could set an equal-area projection with st_transform() .
关于面积,您可以使用st_transform()设置等面积投影。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.