在绘图中嵌入微型绘图

发布于 2024-12-10 20:55:06 字数 363 浏览 0 评论 0原文

有谁知道将绘图嵌入到其他绘图中以生成类似下面的模型的通用方法?

我知道在点阵中你可以用 print(..., more=TRUE, Positions=...) 来完成,如 这个问题,我想 ggplot 也有一个解决方案(但我不太擅长 ggplot)。问题是我想将使用标准图形包的生存包中的常规图嵌入到格子图中。

嵌入图的模型

提前致谢!

Does anybody know of a general way to embed plots into other plots to produce something like the mockup below?

I know that in lattice you can do it with print(..., more=TRUE, positions=...) as explained in this question, and I guess ggplot has a solution to it aswell (but I'm not very good with ggplot). The problem is that I want to embed a regular plot from the survival package that use the standard graphics package into a lattice plot.

A mockup of an embedded plot

Thanks in advance!

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

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

发布评论

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

评论(3

_畞蕅 2024-12-17 20:55:07

您可以尝试 gridBase 包,它提供了一些集成基础图形和基于网格的图形(包括lattice和ggplot2)的功能。下面的示例将基本图形图嵌入到点阵图中。

library(lattice)
library(gridBase)
library(grid) 

plot.new()
pushViewport(viewport())
xvars <- rnorm(25)
yvars <- rnorm(25)
xyplot(yvars~xvars)
pushViewport(viewport(x=.6,y=.8,width=.25,height=.25,just=c("left","top")))
grid.rect()
par(plt = gridPLT(), new=TRUE)
plot(xvars,yvars)
popViewport(2)

更多详细信息请参见:http://casoilresource.lawr.ucdavis.edu/drupal/node/1007
在这里: http://cran.r-project.org/ web/packages/gridBase/vignettes/gridBase.pdf

You could try the gridBase package which provides some functionality for integrating base and grid-based graphics (including lattice and ggplot2). The example below embeds a base graphics plot inside of a lattice plot.

library(lattice)
library(gridBase)
library(grid) 

plot.new()
pushViewport(viewport())
xvars <- rnorm(25)
yvars <- rnorm(25)
xyplot(yvars~xvars)
pushViewport(viewport(x=.6,y=.8,width=.25,height=.25,just=c("left","top")))
grid.rect()
par(plt = gridPLT(), new=TRUE)
plot(xvars,yvars)
popViewport(2)

More detail here: http://casoilresource.lawr.ucdavis.edu/drupal/node/1007
And here: http://cran.r-project.org/web/packages/gridBase/vignettes/gridBase.pdf

美羊羊 2024-12-17 20:55:07

查看教学演示包 TeachingDemos 包 - 和 < code>subplot() 函数 它也可能在格子上工作 - 但还没有尝试过。

Check out the Teaching Demos package package TeachingDemos package - and the subplot() function It might work on the lattice as well - haven't tried it though.

悍妇囚夫 2024-12-17 20:55:06

这是一种相反的方法,在基本图形中使用 ggplot2 图形:

require(ggplot2)
require(grid)

plot(sin, -pi, 2*pi)
qp <- qplot(mpg, wt, data=mtcars)
print(qp, vp=viewport(.8, .75, .2, .2))

在此处输入图像描述

And here is a way to do it the other way around, ggplot2 graphic in a base graphic:

require(ggplot2)
require(grid)

plot(sin, -pi, 2*pi)
qp <- qplot(mpg, wt, data=mtcars)
print(qp, vp=viewport(.8, .75, .2, .2))

enter image description here

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