开发者学堂课程【大数据之 R 语言速成与实战:R的图形组合、图形布局的精细控制】学习笔记,与课程紧密联系,让用户快速学习知识。
课程地址:https://developer.aliyun.com/learning/course/363/detail/4332
R 的图形组合、图形布局的精细控制
内容简介:
一、图形组合
二、图形布局的精细控制
一、图形组合
(一)par()函数的 mfrow 参数
attach(mtCar s)
opar <- par (no.readonly=TRUE)2
par (mfrow=c(2,2))
>plot(wt,mpg,main="wt vs mpg")
> plot(wt,disp,main="wt vs disp")
hist(wt,main="Histogr am of wt''
)
boxplot(wt,main="Boxplot of wt"
)
> par(opar)
> detach(mtcars)
> attach(mtcars)
> opar <-par(no.readonly=TRUE)
> par(mfrow=c(3,1))
> hist(wt)
> hist(mpg)
>hist(disp)
> par(opar)
> detach(mtcars)
> attach(mtcars)
>layout(matrix(c(1,1,2,3)),2,2,byrow=TRUE)
Error in layout(matrix(c(1,1,2,3)),2,2,byrow=TRUE):
unused argument(byrow = TRUE)
>layout(matrix(c(1,1,2,3),2,2,byrow=TRUE))
>hist(wt)
> hist(mpg)
>hist(disp)
> par(opar)
> detach(mtcars)
(二) layout()函数
> attach(mtcars)
>layout(matrix(c(1,1,2,3)),2,2,byrow=TRUE),widths=c(3,1),
heights=c(1,2)
>hist(wt)
Error in plot. new(): figure margins too large
layout(matrix(c(1.1.2.3),2,2,byrowe=TRuE),widths=c(3.1),heights=c(1.1))
>hist(wt)
>hist(mpg)
>hist(disp)
> detach(mtcars)
二、图形布局的精细控制
●par()函数的fig参数
attach(mtcars)
>layout(matrix(c(1,1,2,3),2,2,byrow=TRUE),widths=c(3,1),heights=c(1,2))
> hist(wit)
Error in plot.new0
():figure margins too large
>layout(matrix(c(1,1,2,3
),2,2,byrow=TRUE),widths=c(3,1),heights=c(1,1))
>hist(wt)
>hist(mpg)
>hist(disp)
> detach(mtcars)
> opar <- par (no. readonly=TRUE)
> par(fig=c(0, 0.8,0,0.8)) plot(mtcars$wt,mtcars$mpg,xlab="Gallon",ylab="weight")
>par(fig=c(0.65,1,0,0.8))
> boxplot (mtcarsSmpg,axes=FALSE)
>par (fig=c(0,0.8,0,0.8))
>plot(mtcars$wt,mtcars$mpg,xlab="Gallon",ylab="weight")
>par(fig=c(0.65,1,0,0.8),new=TRUE)
>boxplot(mtcarsSmpg,axes=FALSE)
>par(fig=c(0,0.8,0.55,1),new=TRUE)
>boxplot(mtcars$wt,horizontal=TRUE,axes=FALSE)