在 R 中实现具有不同绘图宽度的多个绘图 [英] Achieving multiple plots with different plotting widths in R

查看:43
本文介绍了在 R 中实现具有不同绘图宽度的多个绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在单个绘图窗口中创建多个绘图,其中每个绘图的面板宽度与每个绘图的 xlim 成正比.

I want to create multiple plots in a single plotting window in which the width of the panels of each plot are proportional to xlim of each plot.

目前我使用:

layout(matrix(c(1:8,10,9), 5, 2, byrow = FALSE), widths=2)       
layout.show(10)

基本上,我希望将 width 单独应用于每个图而不是列中的所有图.这样做的最佳方法是什么?

Basically, I would like width to be applied individually to each plot rather than to all the plots in a column. What is the best way of doing this?

推荐答案

layout 仅当绘图可以排列在规则网格上时才有效,但它们不必具有相同的宽度.

layout only works if the plots can be arranged over a regular grid, but they need not have the same widths.

layout(
  matrix(
    c(1,1,2,3,3,2,4,5,5,6,6,6), 
    nc=3, byrow = TRUE
  )
)
layout.show(6)

如果你想要一些非常不规则的东西,你可以使用par(fig=...,new=TRUE).

If you want something really irregular, you can use par(fig=...,new=TRUE).

plot.new()
par(mar=c(2,2,1,1))
k <- 4
f <- function() 
  plot(rnorm(20),rnorm(20), xlab="", ylab="", main="", las=1)
for(i in 1:k) {
  par(fig=c(0,i/(k+1), (i-1)/k, i/k), new=TRUE)
  f()
  par(fig=c(i/(k+1),1, (i-1)/k, i/k), new=TRUE)
  f()
}

这篇关于在 R 中实现具有不同绘图宽度的多个绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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