我希望得到一张带有南海框架的中国地图作为附件.中国边界线和行政形状文件可以从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)
Run Code Online (Sandbox Code Playgroud)
Graphicsusr
参数定义要绘制的坐标系区域,而不是要绘制的画布区域。该区域由图形参数控制plt
。
有关详细信息,请参阅help(par)
:
\n\n\nRun Code Online (Sandbox Code Playgroud)\n(...)\n\xe2\x80\x98plt\xe2\x80\x99 A vector of the form \xe2\x80\x98c(x1, x2, y1, y2)\xe2\x80\x99 giving the\n coordinates of the plot region as fractions of the current\n figure region.\n(...)\n\xe2\x80\x98usr\xe2\x80\x99 A vector of the form \xe2\x80\x98c(x1, x2, y1, y2)\xe2\x80\x99 giving the extremes\n of the user coordinates of the plotting region. When a\n logarithmic scale is in use (i.e., \xe2\x80\x98par("xlog")\xe2\x80\x99 is true, see\n below), then the x-limits will be \xe2\x80\x9810 ^ par("usr")[1:2]\xe2\x80\x99.\n Similarly for the y-axis.\n(...)\n
您可以通过调用par()
(或者,如果您只想查看特定参数,par(c("plt","usr"))
.
在您的情况下,您似乎想要xleft = 107, ybottom = 0, xright = 122, ytop = 21
在插图中绘制矩形 ( ) 给出的范围,因此您需要usr
使用这些值进行定义。关于您想要绘图的画布区域,您可能需要进行一些实验。c(0.76, 0.935, 0.195, 0.45)
对我来说效果很好,但我猜这可能取决于各种设置,并且对您来说可能会有所不同。
无论如何,请尝试这样的事情:
\n\npar(plt = c(0.76, 0.935, 0.195, 0.45))\npar(usr = c(107, 122, 0, 21))\n
Run Code Online (Sandbox Code Playgroud)\n
归档时间: |
|
查看次数: |
222 次 |
最近记录: |