如何在R基座中绘制南海中国地图

时间:2018-07-08 03:30:21

标签: r gis

我想获得一张带有南中国海框架的中国地图。 中国分界线和行政区划文件可以从以下位置下载 https://github.com/jimrpy/jimrpy.github.io/blob/master/epidemiology/Archive.zip

我的代码如下,我不知道如何设置“ usr”,如何修改代码?

library(maps)
library(rgdal)

china_blank <- readOGR(dsn = "~/China/",
                      layer = "China_Province")
china_line <- readOGR(dsn = "~/China/",
                      layer = "China_Boundary_Nineline")

china_blank <- spTransform(china_blank, CRS("+init=epsg:4326"))
china_line <- spTransform(china_line, CRS("+init=epsg:4326"))

map(china_blank)
map.axes()   
par(usr = c(73, 136, 0, 54))
rect(xleft = 107, ybottom = 0, xright = 122, ytop = 21, col = "white")
map(china_line, xlim = c(108, 122), ylim = c(0, 21), add =T)

enter image description here

1 个答案:

答案 0 :(得分:0)

usr图形参数定义要绘制的坐标系区域,而不是要绘制的画布区域。该区域由plt图形参数控制。

有关详细信息,请参见help(par)

(...)
‘plt’ A vector of the form ‘c(x1, x2, y1, y2)’ giving the
      coordinates of the plot region as fractions of the current
      figure region.
(...)
‘usr’ A vector of the form ‘c(x1, x2, y1, y2)’ giving the extremes
      of the user coordinates of the plotting region.  When a
      logarithmic scale is in use (i.e., ‘par("xlog")’ is true, see
      below), then the x-limits will be ‘10 ^ par("usr")[1:2]’.
      Similarly for the y-axis.
(...)

您可以通过调用par()来查看当前的参数集(或者,如果只想查看特定的参数,可以调用par(c("plt","usr"))

在您的情况下,您似乎想在插图中绘制矩形(xleft = 107, ybottom = 0, xright = 122, ytop = 21)给出的范围,因此您将希望使用这些值来定义usr。关于需要绘图的画布区域,您可能需要尝试一下。 c(0.76, 0.935, 0.195, 0.45)对我来说效果很好,但是我猜测这可能取决于各种设置,并且可能与您有所不同。

无论如何,请尝试以下操作:

par(plt = c(0.76, 0.935, 0.195, 0.45))
par(usr = c(107, 122, 0, 21))