在任意位置绘制图像

发布于 2024-10-09 00:13:51 字数 511 浏览 0 评论 0原文

我想将图像添加到绘图中。我可以使用 image 函数成功地将图像放置在 [0 1] 范围内,但我希望能够将其绘制在另一个位置。这是一个例子:

require(rgdal)
require(RgoogleMaps)
bb <- qbbox(c(40.702147,40.711614,40.718217),c(-74.015794,-74.012318,-73.998284), TYPE = "all", margin = list(m=rep(5,4), TYPE = c("perc", "abs")[1]));

MyMap <- GetMap.bbox(bb$lonR, bb$latR,destfile = "MyTile3.png", maptype = "satellite")
plot(0:20,0:20)
image(MyMap$myTile,col=attr(MyMap$myTile,"COL"),add=TRUE)

这创建了一个位于原点的小地图,我想让它跨越我选择的范围(实际上它是实际的纬度/经度)。

I would like to add an image to a plot. I can sucessfully place the image in the range [0 1] using the image function, but I would like to be able to plot it in an alternate location. Here is an example:

require(rgdal)
require(RgoogleMaps)
bb <- qbbox(c(40.702147,40.711614,40.718217),c(-74.015794,-74.012318,-73.998284), TYPE = "all", margin = list(m=rep(5,4), TYPE = c("perc", "abs")[1]));

MyMap <- GetMap.bbox(bb$lonR, bb$latR,destfile = "MyTile3.png", maptype = "satellite")
plot(0:20,0:20)
image(MyMap$myTile,col=attr(MyMap$myTile,"COL"),add=TRUE)

This creates a tiny map located at the origin, I would like to have it span a range of my choosing (In reality it's actual latitude/longitude).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

信愁 2024-10-16 00:13:51

使用 image() 的 x 和 y 参数。请注意 image(x) 如何适用于矩阵,或由 $x 和 $y 向量以及 $z 矩阵组成的列表,但您也可以显式传入 image(x = xvec, y = yvec, z = zmat) 。

因此,粗略地说(您需要检查您是否想要单元格中心 [dim(z)] 还是单元格角 [dim(z)+1])

    dims <- dim(seqMyMap$myTile)
    image(x = seq(minX, maxX, length = dims[1]), y = seq(minY, maxY, length = dims[2]), z =  seqMyMap$myTile,col=attr(MyMap$myTile,"COL"),add=TRUE) 

另外,请阅读 ?image - 它确实解释了这一点。

Use the x and y arguments to image(). Note how image(x) will work for a matrix, or a list composed of $x and $y vectors and $z matrix, but you can also pass in image(x = xvec, y = yvec, z = zmat) explicitly.

So, roughly (you will need to check whether you want cell centres [dim(z)] or cell corners [dim(z)+1])

    dims <- dim(seqMyMap$myTile)
    image(x = seq(minX, maxX, length = dims[1]), y = seq(minY, maxY, length = dims[2]), z =  seqMyMap$myTile,col=attr(MyMap$myTile,"COL"),add=TRUE) 

Also, read ?image - it does explain this.

缱倦旧时光 2024-10-16 00:13:51

另请查看教学演示包中的 subplot 函数,或与 my.symbols 一起使用的 ms.image(也在教学演示中)。

Also look at the subplot function in the TeachingDemos package, or ms.image for use with my.symbols (also in TeachingDemos).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文