Custom axes
Axis ()
X <-C (1:10) Y <-XZ <-10/Xopar <-par (No.ReadOnly =TRUE) par (Mar = c (5,4,4,8) +0.1Plot (x, y, type ="B", PCH =, col ="Red", Yaxt ="N", lty =3, Ann =FALSE) lines (x, z, type ="B", PCH =Col ="Blue", lty =2) axis (2, at = x, labels = x, Col.axis ="Red", Las =2) axis (4, at = z, labels = round (z, digits =2), Col.axis ="Blue", Las =2, Cex.axis =0.7, TCK =-0.01) Mtext ( "y=1/x4, line = 3, Cex.lab = 1, Las = 2 blue "" title (an Example of Creative Axes" x values ", Ylab = "y=x ) par (OPAR)
The at and labels are consistent, indicating the position of the drawing scale.
Minor tick marks
The Minor.tick () function of the Hmisc package
Library (Hmisc) Minor.tick (nx=2,ny=3,tick.ratio=0.5)
where NX and NY refer to the number of intervals divided between two major tick marks, Tick.ratio represents the size of the minor tick line relative to the main tick mark.
Reference line
Abline (H=c (1,5,7), V=seq (1,ten,2), lty=2,col="Blue")
H is the horizontal guide and V is the vertical reference line (position 1, 3, 5, 7, 9)
Legend
Legend"TopLeft0.05, title = drug type ", C ( "a" "b1, 2), PCH = C (15, 17), col = C ( " Span style= "color: #800000;" >red " " blue
Inset distance (s) from the margins as a fraction of the plot region when legend was placed by keyword.
Text callout
Text (location, ' Text to place ', POS,...) Adds text to the inside of the plot area. Location can be set for a pair of x, y coordinates, or location (1) with the mouse.
Mtext ("Text to place", Side,line=n,...) Adds text to one of the four edges of the graph.
Graphic combinations
Function par () or layout ()
Par ()
Attach (mtcars) opar <-par (No.ReadOnly = TRUE) par (Mfrow = C (2, 2 " "" plot (WT, DISP, main = "scatterplot of WT vs Disp" ) hist (WT, main = Histogram of Wt ") boxplot (WT, main = "boxplot of Wt" ) par ( Opar) Detach (mtcars)
Mfrow=c (2,2) indicates that 2 rows and 2 columns are populated by rows, and Mfcol=c (2,2) indicates that 2 rows and 2 columns are populated by columns.
Layout ()
Attach (Mtcars) layout (Matrix (c (2, Byrow = TRUE), widths = C (1), heights = C (2) ) hist (WT) hist (MPG) hist (disp) detach (mtcars)
Widths and heights represent the relative width and relative height of each column, the first row is 3, the second row is 1, the first column is Gao Jianbi 1, and the second Lego Jimby 2. The absolute width is specified by the LCM (), such as WIDTHS=LCM (5).
Where 2, 2 means the row is arranged in 2 rows and 2 columns.
Fine-grained control of graphical layouts
Fig ()
Opar <-par (No.ReadOnly=TRUE) par (Fig= C (0,0.8,0,0.8) plot (MTCARS$WT, Mtcars$mpg, Xlab="Miles Per Gallon", Ylab="Car Weight") par (Fig= C (0,0.8,0.55,1),New=TRUE) BoxPlot (MTCARS$WT, Horizontal= TRUE, axes =FALSE) par (Fig= C (0.65,1,0,0.8),New=TRUE) BoxPlot (mtcars$mpg, axes=FALSE) Mtext ("Enhanced Scatterplot", side =3, outer =TRUE, Line= -3) par (OPAR)
02 Graphics First Order