一、mfrow布局
- #mfrow或者mfcol
- par('mfrow')
- par('mfcol')
- opar <- par(no.readonly = TRUE)#将可以修改的变量储存起来
- par(mfrow=c(2,2))
- par('mfrow')
- plot(pressure,col="red",main="Pic 1")
- barplot(table(mtcars$cyl),col = c("red","cyan","orange"),main = "Pic 2")
- hist(rivers,breaks = 30,col = "pink",main = "Pic 3")
- pie(c(1,3,4,2),labels = c("A","B","C","D"),main = "Pic 4")
- par(mfrow=c(2,2))
- layout.show(4)
- par(mfcol=c(2,2))
- layout.show(4)#与上面的不同,1234摆放位置不同
- par(mfrow=c(1,2))#1行2列
- barplot(1:6)
- pie(1:6)
- par(mfrow=c(2,1))#2行1列
- barplot(1:6)
- hist(rivers)
- par(mfrow=c(2,3))#2行3列
- layout.show(6)
- hist(rivers)
- hist(rivers)
- hist(rivers)
- hist(rivers)
- hist(rivers)
- hist(rivers)
- par(mfrow=c(2,1))#2行1列
- hist(rivers)
- barplot(1:6)
- #想让上下两张图离得近些
- layout.show(2)
- par('mar')
- par(opar)
- # 5.1 4.1 4.1 2.1
- par(mfrow=c(2,1))#2行1列
- par(mar=c(5.1,4.1,4.1,2.1))
- hist(rivers)
- par(mar=c(5.1,4.1,0,2.1))
- barplot(1:6)#画图前调整下左上右
- par(mfrow=c(2,2))#2行2列
- layout.show(4)
- par('mar')
- par(mar=c(0,4.1,4.1,2.1))
- hist(rivers)#贴着下边
- par(mar=c(5.1,0,4.1,2.1))
- barplot(1:6)#贴着左边
- par(mar=c(5.1,4.1,0,2.1))
- hist(rivers)#贴着上边
- par(mar=c(5.1,4.1,4.1,0))
- hist(rivers)#贴着右边
- #以上都是规整的布局
复制代码
2行2列
1行2列
2行1列
二、layout 布局
- layout(mat = matrix(c(1,2,3,4)))
- layout.show(4)
- layout(mat = matrix(c(1,2,3,4),nrow=2,byrow=T))
- matrix(c(1,2,3,4),nrow=2)
- matrix(c(1,2,3,4),nrow=2,byrow=T)#绘图位置不同
- layout.show(4)
- hist(rivers)
- plot(women)
- barplot(1:6)
- pie(1:6)
- matrix(c(1,1,2,3),nrow=2,byrow=T)
- layout(mat = matrix(c(1,1,2,3),nrow=2,byrow=T))
- layout.show(3)
- hist(rivers)
- plot(women)
- barplot(1:6)
- matrix(c(1,2,1,3),nrow=2,byrow=T)
- layout(mat = matrix(c(1,2,1,3),nrow=2,byrow=T))
- layout.show(3)
- hist(rivers)
- plot(women)
- barplot(1:6)
- matrix(c(1,0,0,2,2,0,3,3,3),nrow=3,byrow=T)
- layout(matrix(c(1,0,0,2,2,0,3,3,3),nrow=3,byrow=T))
- layout.show(3)
- hist(rivers)
- plot(women)
- barplot(1:6)
- layout(matrix(c(1,1,2,3),nrow=2,byrow=T))
- layout.show(3)
- layout(matrix(c(1,1,2,3),nrow=2,byrow=T),width = c(2,1))
- layout.show(3)
- layout(matrix(c(1,1,2,3),nrow=2,byrow=T),width = c(2,1),heights = c(1,2))
- layout.show(3)#调整组分高度和宽度
复制代码
layout可调整不规整布局
layout可调整不规整布局
layout可调整不规整布局
|