【发布时间】: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
【问题讨论】:
-
也许可以尝试将
xaxs和yaxs设置为“i”,例如:stat.ethz.ch/pipermail/r-sig-geo/2011-November/013548.html -
感谢您的建议。不幸的是,在这种情况下它不起作用。
标签: r plot raster shapefile sp