ggrepel对象的坐标xy未对齐

问题描述

问题是: 为什么红线与黑线不对齐? 我可以使d在UTM坐标系中具有x和y吗?像x = 5600000,y = 1200000?

library(spData)
library(spDataLarge)
library(tidyverse)
library(sf)
library(tmaptools)
library(grid)
library(ggrepel)
library(ggsflabel)

# first plot
ggplot() +
  geom_sf(data = nz,aes(color = Name)) +
  geom_sf(data = nz_height) +
  geom_sf_text_repel(data = nz_height,aes(label = elevation),min.segment.length = 0) +
  coord_sf(datum = st_crs(nz_height)) +
  theme(
    legend.position = "none"
  )

grid.force()
kids <- childNames(grid.get("textrepeltree",grep = TRUE))

d <- do.call(rbind,lapply(kids,function(n) {
  x <- grid.get(n)
  data.frame(
    x = convertX(x$x,"native",valueOnly = TRUE),y = convertY(x$y,x.orig = convertX(x$x.orig,y.orig = convertY(x$y.orig,valueOnly = TRUE)
  )
}))

panelvp <- grid.grep("panel",grobs = FALSE,viewports = TRUE,grep = TRUE)
downViewport(panelvp)

# add red lines (but not aligned)
grid.segments(unit(d$x,"npc"),unit(d$y,unit(d$x.orig,unit(d$y.orig,gp = gpar(col = "red"))

https://developer.wordpress.org/reference/functions/register_taxonomy/

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)