情节内情节 [英] Plot inside a plot

查看:21
本文介绍了情节内情节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有情节 1

curve(exp(x), from=1, to=5, lwd=5)
curve(150-exp(x), from=1, to=5, lwd=5, col="darkblue",add=T)

在里面我想添加以下情节 2

and inside it i would like to add the following plot 2

par(mar=c(7,7,1,1))
curve(exp(x), from=1, to=5, lwd=7, xlab="chi", ylab="exp(x)", cex.lab=4,axes=F)
axis(1, labels=NA,at=c(0,5))
axis(2, labels=NA,at=c(0,150))
text(1,120,"Alpha",adj=c(0,0),cex=3)
text(3.5,10,"Beta",adj=c(0,0),cex=3)

为了获得以下内容

我还想让情节 2 透明,以便如果情节 2 后面有情节 1 的某些元素,它们仍会显示(就像蓝线一样).同样重要的是图 2 的更大标签以及它的轴上没有标签和刻度线.

I would also like to make plot 2 transparent so that if there are some elements of plot 1 behind plot 2 they will still show (just like the blue line). Also important are the bigger labels of plot 2 and the absence of labels and ticks in it's axes.

这可能吗?请仅基于 R 解决方案(无 ggplot2/无格)

Is this possible? Please only base R solutions (no ggplot2 / no lattice)

推荐答案

好的,这是一个示例,我将其绘制为 10 x 10 英寸的 pdf.(使用 par(fig = ) 等令人沮丧的部分原因是它们的效果在很大程度上取决于绘图设备的大小.)

OK, here's an example, which I plotted to a 10 by 10 inch pdf. (Part of what's frustrating about using par(fig = ) et al. is that their effects are very much dependent on the size of the plotting device.)

编辑添加一些解释:

基本图形绘制参数par("fig") 描述/设置图形区域的位置作为绘图区域"(通常是整个设备,对于单个图形)的比例情节).它采用 c(xmin, xmax, ymin, ymax) 形式的长度为 4 的向量,由 01 之间的数字(比例)组成>.

The base graphic plotting parameter par("fig") describes/sets the location of a figure region as a proportion of the "drawing region" (which is usually the entire device, for single figure plots). It takes a length-4 vector of the form c(xmin, xmax, ymin, ymax) consisting of numbers (proportions) between 0 and 1.

在这里,我使用 grconvertX()grconvertY() 来转换以较大图自身(又名 user") 坐标系转换为 "ndc"(标准化设备坐标)坐标系."user" 坐标系更人性化,而 "ndc" 是(上面提到的警告)par 使用的坐标系(无花果").grconvert*() 调用只是在那里执行它们之间的转换.

Here I use grconvertX() and grconvertY() to convert x-y locations expressed in terms of the larger plot's own (a.k.a. "user") coordinate system into the "ndc" (normalized device coordinates) coordinate system. The "user" coordinate system is more human-user-friendly, while the "ndc" is (with the caveats expressed above) the coordinate system used by par("fig"). The grconvert*() calls are just there to perform the translation between them.

## pdf("fig-in-fig.pdf", width=10, height=10)
curve(exp(x), from=1, to=5, lwd=5)
curve(150-exp(x), from=1, to=5, lwd=5, col="darkblue",add=T)

## Here's the bit I added.
par(fig = c(grconvertX(c(1, 3), from="user", to="ndc"),
            grconvertY(c(50, 125), from="user", to="ndc")),
    mar = c(4,6,1,1),
    new = TRUE)

curve(exp(x), from=1, to=5, lwd=7, xlab="chi", ylab="exp(x)", cex.lab=4,axes=F)
axis(1, labels=NA,at=c(0,5))
axis(2, labels=NA,at=c(0,150))
text(1,120,"Alpha",adj=c(0,0),cex=3)
text(3.5,10,"Beta",adj=c(0,0),cex=3)
## dev.off()

这篇关于情节内情节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆