在另一个角落绘制图表 [英] Drawing a graph in the corner of another

查看:111
本文介绍了在另一个角落绘制图表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何在R的另一个图的角落展示一个小图?

How should I present a small plot in the corner of another plot in R?

推荐答案

像这样:

# Making some fake data
plot1 <- data.frame(x=sample(x=1:10,10,replace=FALSE),
                    y=sample(x=1:10,10,replace=FALSE))
plot2 <- data.frame(x=sample(x=1:10,10,replace=FALSE),
                    y=sample(x=1:10,10,replace=FALSE))
plot3 <- data.frame(x=sample(x=1:10,10,replace=FALSE),
                    y=sample(x=1:10,10,replace=FALSE))

layout(matrix(c(2,1,1,3,1,1),2,3,byrow=TRUE))
plot(plot1$x,plot1$y)
plot(plot2$x,plot2$y)
plot(plot3$x,plot3$y)

矩阵 layout 命令可让您将多个图形排列到一个绘图中。基本上,你把每个小区的数量(按照你要调用的顺序)放到每个小区中,然后不管最后的安排是什么,你的小区布局如何。例如,在上面的例子中,矩阵(c(2,1,1,3,1,1),byrow = TRUE)产生一个看起来像这样的矩阵:

The matrix and layout commands let you arrange multiple graphs into a single plot. Basically, you put the number of each plot (in the order you are going to call it) into each cell, and then whatever the arrangement is ends up being how your plots are laid out. For instance, in the case above, matrix(c(2,1,1,3,1,1),byrow=TRUE) results in a matrix that looks like this:

     [,1] [,2] [,3]
[1,]    2    1    1
[2,]    3    1    1

所以,最后可能会出现如下结果:

So, you can end up with something like this:

编辑添加:

好的,如果您想要在角落中集成一个绘图,您可以使用相同的 layout 命令,只需更改矩阵即可。例如,这是不同的代码:

Okay, so, if you want to integrate a plot in the corner, you can do that using the same layout command by simply changing the matrix. For instance, this is different code:

layout(matrix(c(1,1,2,1,1,1),2,3,byrow=TRUE))
plot1 <- data.frame(x=1:10,y=c(9,10,8,7,3,4,1,2,5,6))
plot2 <- data.frame(x=1:10,y=c(6,7,5,1,2,8,3,10,9,4))
plot(plot1$x,plot1$y,type="o",col="red")
plot(plot2$x,plot2$y,type="o",xlab="",ylab="",main="",sub="",col="blue")

矩阵是:

And the resultant matrix is:

     [,1] [,2] [,3]
[1,]    1    1    2
[2,]    1    1    1

出现的图如下所示:

这篇关于在另一个角落绘制图表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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