r - 如何在基地R中绘制带有南中国海的中国地图
问题描述
我想得到一张以南海框架为附件的中国地图。中国边界线和行政形状文件可以从 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)
解决方案
graphics 参数定义了您想要绘制的坐标系统的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))
推荐阅读
- flutter - 在颤动中将未聚焦的文本字段更改为白色
- python - 根据不同列上的值排列数据框
- android - Flutter构建apk错误:任务':app:compileFlutterBuildRelease'执行失败
- git - Git - 显示最后一次修改是对文件夹的时间
- python - 如何在 Python 中解开子和父 __init__ 方法?
- webapi - 如何为某些应用程序服务禁用动态 WebAPI
- oracle - Oracle 应用程序中基于 SQL*Loader 的并发程序中的数据文件放在哪里?
- javascript - 在导航上设置图像叠加?
- next.js - NextJS 使用文件系统上传/检索图像?
- java - 连接两个有向无环图