首页 文章

xlim和ylim用于绘制R中的 Map ,表现不尽如人意

提问于
浏览
0

我的 Map 也不会导致我期望的行为 . 我使用以下从this question修改的代码在R中创建了一个 Map :

library(maps)
library(mapdata)
library(rgdal)

# Build a basemap of British Columbia projected as BC Environmental Standard Projection
download.file(url="http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip", "ne_110m_admin_0_countries.zip", "auto")
unzip("ne_110m_admin_0_countries.zip")
file.remove("ne_110m_admin_0_countries.zip")

# read shape file using rgdal library
ogrInfo(".", "ne_110m_admin_0_countries")
world <- readOGR(".", "ne_110m_admin_0_countries")
summary(world)  

worldBCESP <- spTransform(world, CRS("+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"))
summary(worldBCESP)  
plot(worldBCESP, xlim=c(642162.8,1870556), ylim=c(457057.2,1421478), col="gray90")

Map 绘制为一个瘦的矩形 . 像这样:
Map plotted with xlim=c(642162.8,1870556), ylim=c(457057.2,1421478)

xlim和ylim基于来自 summary(spu) 的信息,用 rgdal:readOGR. 读入的数据(here)该数据集仅包含不列颠哥伦比亚省的点,而xlim和ylim应该反映这一点 .

当我改变xlim和ylim时,瘦的矩形根本不会改变,但我在矩形内部的 Map 上缩放 . 例如,使用 xlim=c(250000.8,1870556), ylim=c(107057.2,1421478) , Map 看起来像

zoomed out map

如何让 Map 绘制成全尺寸并表示我所追求的程度(仅限于不列颠哥伦比亚省周边地区)? xlim和ylim的工作方式与我现在正在使用的预测数据不同吗?

1 回答

  • 2

    这是RStudio的一个问题 . 要解决它,打开一个文件并写一个图 .

    png("file.png", width=800, height=800)
    
    plot(basemap, xlim=c(0,1870556), ylim=c(157057.2,1421478), col="gray90") #plot basemap
    plot(spu, add=TRUE, border=FALSE, col=spu$SPU) #plot SPUs
    legend('bottomleft', legend = levels(spu$SPU), col = 1:length(levels(spu$SPU)), cex = 1, pch = 16) #plot legend
    title("Lodgepole Pine Seed Planning Units")
    
    dev.off()
    

相关问题