【问题标题】:Can't limit boundaries of a plotted shapefile properly无法正确限制绘制的 shapefile 的边界
【发布时间】:2018-02-05 19:01:52
【问题描述】:

我无法真正设置我绘制的 shapefile 的边界。我首先绘制 shapefile 以首先以度为单位获得漂亮的 x 和 y 标签,然后绘制数据。最后,我再次在数据上绘制我的 shapefile。 ylim 是可变的,但 xlim 似乎完全依赖于 ylim 的变化,因为我不能改变 xlim 本身。当我更改 ylim 而不更改 xlim 时,它只会有所不同,就像它是纵横比问题一样。

我想将 x 轴限制在 8.5 到 11.5 度之间。

相关 shapefile 和栅格的链接:https://www.dropbox.com/sh/l42mty01mwtm8qc/AADqjNbGkmNwx3o9aFceGrkya?dl=0

我的代码:

library(rgeos)
library(rgdal)
library(raster)

Sys.setlocale(category = "LC_ALL", locale = "C") # In the case German Umlauts are a problem while reading the shapefile
map <- readOGR("C:\\Path\\NATRAUM_MR_utm32.shp")

# Exclude unnecessary regions
map <- subset(map, NATREGNR != 3) 
map <- subset(map, NATREGNR != 4)
map <- subset(map, NATREGNR != 9)
map_wgs84 <- spTransform(map, crs(raster.percent.change.rcp85.1971_2005.2071_2100))

# Pixelplot
par(mar = c(3, 3, 2, 1))  # For saving pictures through a device like pdf

m <- plot(map_wgs84, axes=TRUE, xlim = c(8.5, 11.5), ylim=c(51.35, 53.15), cex = .5,
      bty = "n")

# Colortable for legend
colTab <- c("#0033CC", "#3366FF", "#6699FF","#99FFFF", "#FFCC99","#FF9933", "#FF4D00","#660000")

N <- length(colTab)
breaks <- seq(-2, 2,  length.out= N+1 )

plot(raster.percent.change.rcp85.1971_2005.2071_2100, col = colTab, breaks = breaks,
       axis.args = list(cex.axis = 1, at = breaks, labels = breaks, mgp = c(1, 0, 0), tck = 0.1),
       legend.args = list(text='Change [%]', side=4, font=2, line=1.75, cex=0.7),
        add = TRUE

)

plot(map_wgs84, add = TRUE)  # Plotting shapefile over data

【问题讨论】:

标签: r plot raster shapefile sp


【解决方案1】:

您需要调整绘图窗口的大小。您可以使用par(fin=c(x,y))png() 设置一个有效的比率,并在代码中修复它。

这是因为对于地图,强制执行正确的纵横比(垂直和水平范围的比率)。对于平面数据,方面为 1。对于角度数据(经度/纬度),它因纬度而异。

有一些数据。

library(raster)
p <- shapefile(system.file("external/lux.shp", package="raster"))

比较:

par(fin=c(6,6))
plot(p, axes=T, xlim=c(6,6.2), ylim=c(49.6, 49.8))

par(fin=c(4, 6))
plot(p, axes=T, xlim=c(6,6.2), ylim=c(49.6, 49.8))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 1970-01-01
    • 2019-10-25
    • 1970-01-01
    • 2022-08-03
    相关资源
    最近更新 更多