zoukankan      html  css  js  c++  java
  • R作图-多图布局

    mfrow 基于par布局

    • 注意设置par时,先保存一下原始图像参数。
    attach(mtcars)
    opar=par(no.readonly = T)
    par(mfrow=c(3,2)) #按行填充,行数为3,列数为2,mfcol按列填充
    hist(wt)
    hist(mpg,ann=F)
    hist(disp,ann=F)
    par(opar)
    detach(mtcars)
    

    layout 基于矩阵布局

    attach(mtcars)
    layout(matrix(c(1,1,2,3),2,2,byrow=T),widths=c(3,1),heights=c(1,2))
    hist(wt)
    hist(mpg)
    hist(disp)
    detach(mtcars)
    

    fig 自定义布局

    • 主要是按照图层比例,自定义放置子图位置
    attach(mtcars)
    opar=par(no.readonly = T)
    par(fig=c(0,0.8,0,0.8))  #fig=c(x1,x2,y1,y2),4个数值分别为左下角到左,右,下、上边界的距离与对应边的百分比数
    plot(wt,mpg,xlab="Miles Per Gallon",ylab="Car Weight")
    par(fig=c(0,0.8,0.55,1),new=T) #占据横向范围0~0.8,纵向范围0.55~1,new=T设定添加图到现有图上
    boxplot(wt,horizontal=T,axes=F) #horizontal=T旋转90度
    par(fig=c(0.65,1,0,0.8),new=T) #占据横向范围0.65~1,纵向范围0~0.8
    boxplot(mpg,axes=F)
    mtext("Enhanced Scatterplot",side=3,outer=T,line=-3)
    par(opar)
    detach(mtcars)
    
  • 相关阅读:
    2-2. 然后是几点(15)
    2-1. 厘米换算英尺英寸(15)
    2-0. 整数四则运算(10)
    忙碌的下半学期
    ACM 第十九天
    ACM 第十八天
    ACM 第十七天
    凸包模板
    极角排序常用方法
    ACM 第十六天
  • 原文地址:https://www.cnblogs.com/xiaofeiIDO/p/12529935.html
Copyright © 2011-2022 走看看