小编Jim*_*all的帖子

在geom_sf_text中,如何在美学上轻推x和y?

我想使用 sf 微调 ggplot2 中文本的 x 和 y 位置。文字的对齐可以在美学中修改,然后需要nudge也同样修改,但是nudge_x和nudge_y不能用于美学。

使用 sp 和强化数据框,我可以修改美学中的 x 和 y ( x=(x+hBump), y=(y+vBump) 。我不知道这在 sf 中是否可行。

以下是一些数据:

Cities <- read.table( text=
  "City long    lat hJust   vJust   hBump   vBump
  GrandJunction -108.550649 39.063871   1   1   -1100   -1000
  Gunnison  -106.925321 38.545825   0   1   0   -1000
  Tincup    -106.47836  38.754439   1   0   0   800",
  header=TRUE )
Run Code Online (Sandbox Code Playgroud)

转换为 sf

Cities.sf <- st_as_sf(
  x = Cities, 
  coords = c("long", "lat"),
  crs = "+proj=longlat +datum=WGS84"
)
Run Code Online (Sandbox Code Playgroud)

ggplot(coord_sf 只是为了让标签不会脱落)

ggplot(Cities.sf) + 
  geom_sf() + 
  coord_sf(xlim …
Run Code Online (Sandbox Code Playgroud)

r ggplot2 r-sf

6
推荐指数
2
解决办法
1956
查看次数

使用 terra 中的行/列索引对栅格进行子集化

我正在尝试在 terra 包中按行号和列号对栅格进行子集化。显然,这在栅格中很容易,至少没有地理范围和 crs: 使用行/列索引对栅格进行子集化。但我无法让它在陆地上工作。必须有一个简单的方法。terra::subset 仅选择栅格的图层。

期待有人问为什么:在对高程栅格进行采样并计算坡度和坡向之前,我用行和列填充了栅格,这依赖于相邻像元。现在我需要去掉那些填充的行和列。

library(terra)
EXT <- c( -108, -105, 39, 42 )
R <- rast( extent=EXT, ncol=14, nrow=14, crs="epsg:4326" )
R[] <- 1:ncell(R)

# Now try to strip off the outer 2 rows and columns
crop( x=R, y=ext( 3, 12, 3, 12 ) )
# Error: [crop] extents do not overlap

# Normal R-style subsetting also does not work,
# just gives values of that subset
R[ 3:12, 3:12 ]
Run Code Online (Sandbox Code Playgroud)

gis r raster terra

3
推荐指数
1
解决办法
1023
查看次数

标签 统计

r ×2

ggplot2 ×1

gis ×1

r-sf ×1

raster ×1

terra ×1