R Language Drawing 002-page layout

Source: Internet
Author: User

par () , layout () , Split.screen () function

1. The parameters of the par () function are detailed

The function par () can be used to set or get the graphical parameters, par () itself (without any parameters in parentheses) returns the current graphical parameter setting (a list), and to set the graph parameters, the form of par (tag = value), where the detailed description of tag is shown in the following column, Value is the parameter values, for example:

Par (Mar = C (4, 4, 1, 0.5), BG = "yellow")?? # set margin parameters and background color

Par (pin=c (2,3))?? #定义图形为2英寸宽, 3 "high

Par (lwd=2,cex=1.5)?? #线条为默认的2倍宽, the symbol is 1.5 times times the default

Par (cex.axis=0.75,font.axis=3)?? #坐标轴文字缩放为原来的75%, italic

Col, PCH, CeX, lty, lwd the meaning of these parameters is basically the same as the parameters in par (), except that in par () These parameters can only be set to a single value, and here a vector is set, and the value of the vector is applied to each element in turn. If the vector length is shorter than the number of elements, then the vector will be recycled until all the elements are drawn, in fact, the cyclic use of vectors is also a major feature of the R graph parameters.

2. Layout ():mat with the matrix to set the partition of the window, the 0 element of the matrix indicates that the position does not draw, non-0 elements must include a continuous integer value starting from 1, for example: 1 ... N, sets the order of the graphs by the size of the non-0 elements. Widths is used to set the width of different columns of the window, heights sets the height of the non-peers. The Mfcol, and Mfrow parameters of par () also have a function similar to layout. The general form of the layout () function is layout (MAT), Mat is a matrix, and the number of MAT elements determines that an output device is divided into several identical elements.

Layout (Matrix (c (1,2,3,0,2,3,0,0,3), nr=3)) matrix has 9 elements, in this form:

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

[1,]??? 1??? 0??? 0

[2,]??? 2??? 2??? 0

[3,]??? 3??? 3??? 3

By passing this matrix into the layout function, we can get this output device

Thus, the figure1 occupies a lattice in the upper left corner, and the first two squares of the second row belong to the three figure2,figure3 that occupy the bottom row.

Layout (Matrix (1:4,2,2)) #将当前装置分割为矩阵2行2列的布局

???? [, 1] [, 2]

[1,]??? 1??? 3

[2,]??? 2??? 4

Layout.show (4) #显示绘图装置分割好的1到4部分;

Look at the differences between the following code:

Layout (Matrix (1:6,3,2)) #将当前装置分割为3行2列的布局

???? [, 1] [, 2]

[1,]??? 1??? 4

[2,]??? 2??? 5

[3,]??? 3??? 6

Layout.show (6) #显示布局的编号

Layout (Matrix (1:6,2,3)) #将当前装置分割为2行3列布局

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

[1,]??? 1??? 3??? 5

[2,]??? 2??? 4??? 6

Layout.show (6) #显示布局编号

Layout (Matrix (c (1:3,3), 2,2)) #建立矩阵, dividing the unit into 3 parts

???? [, 1] [, 2]

[1,]??? 1??? 3

[2,]??? 2??? 3

Layout.show (3) #显示布局编号

M<-matrix (1:4,2,2); M? #建立矩阵m, 2 columns, 2 rows

Layout (M,widths=c (1,3), Heights=c (3,1)) #将当时装置按照m进行划分, width ratio is 1:3, height ratio is 3:1

Layout.show (4)

M<-matrix (c (1,1,2,1), 2,2); M? #建立矩阵

Layout (M,widths=c (2,1), heights=c) #按照矩阵编号进行分割, with the same number, width 2:1, height 1:2

Layout.show (2)

M<-matrix (0:3,2,2) #, note that this matrix has 0, 0 is not drawing, you can see the effect

Layout (M,c (1,3), C (1,3)) #行为1:3, column 1:3

Layout.show (3)

2. Case one:

Attach (Mtcars)

Opar<-par (no.readonly=true) #保存默认设置

Par (Mfrow=c (2,2)) #将画布分割为2 * * pattern

Plot (wt,mpg,main= "scatterplot of WT vs. mpg")

Plot (wt,disp,main= "scatterplot of WT vs DISP")

hist (WT, main= "histogram of WT")

BoxPlot (wt,mian= "boxplot of WT")

Par (OPAR)

Detach (Mtcars)

Case TWO:

Attach (Mtcars)

Opar<-par (No.readonly=true)

Par (Mfrow=c (3,1) # divides the canvas into 3 rows, 1 columns of landscape

hist (WT)

hist (MPG)

hist (disp)

Par (OPAR)

Detach (Mtcars)

Case THREE:

Attach (Mtcars)

Layout (Matrix (c (1,1,2,3), 2,2,byrow = TRUE))

hist (WT)

hist (MPG)

hist (disp)

Detach (Mtcars)

??

3. Split.screen function

Split.screen (c): The current painting device is divided into 2 pieces, 1th number 2nd, respectively, can be selected through screen (1) or screen (2), but at this time the split is usually split horizontally, if the detailed segmentation, you can use the layout function.

Screen () Select the drawing area, screen (n =, new = TRUE)

Eraser.screen () Clear the selected drawing area, Erase.screen (n =)

Close.screen () Removes a specific selection, Close.screen (n, all.screens = FALSE)

Screen????? Numbers in the Figs

After the Split.screen () is split, the rest of the functions can be used. If no parameter, returns the number of the segmented small area, appearing as a vector

Close.screen exits the split, if the current area is closed (that is, the segmented small area), the next small area is entered, close.screen (all = TRUE) indicates the exit split state

Example:

Par (bg = "white") # Black background

Split.screen (C (2, 1))?????? # divided into top and bottom two screens, 2 rows 1 columns

Split.screen (C (1, 3), screen = 2)? # 2 screen is subdivided into 3 small screens, that is, 2 screens are divided into 1 rows and 3 columns

Screen (1) # 1 Screens selected

Plot (10:1)

Screen (4) # Select 4 Screens

Plot (10:1)

Close.screen (all = TRUE)??? # Exit Split-screen mode

Split.screen (C (2, 1)) # divided into top and bottom 2 screens

Split.screen (C (1, 2), 2)??? # Divide the screen into 2 screens

Plot (1:10)????????????????? # in the 3rd screen drawing, this is the currently active screen

Erase.screen ()????????????? # Clear the current screen

Plot (1:10, Ylab = "Ylab 3")

Screen (1)?????????????????? # select 1 screen

Plot (1:10)

Screen (4)?????????????????? # Activate 4 screen

Plot (1:10, Ylab = "Ylab 4")

Screen (1, FALSE)??????????? # 1 screen is returned, but no 1 screen is cleared and if screen (1,true), clear 1

Plot (10:1, axes = FALSE, lty = 2, Ylab = "")? # dot

Axis (4)???????????????????? # Right Plus axes

Title ("Plot 1")

Close.screen (all = TRUE)??? # Exit Split-screen mode

R Language Drawing 002-page layout

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.