R language 3.16 high-level drawing

The logic command
add=T in the figure means adding a picture to the original picture. The default is add=F, that is, the new picture replaces the original picture.
Axes=F, it means that the graph is drawn without axes, and the default value is axes=T.
The logarithm of the data
log=”x” means the logarithm of the x-axis data, log=”y” means the logarithm of the y-axis data, log=”xy” means the logarithm of the x-axis and y-axis data are taken at the same time.
type command
type=”p”, scatter graph (default); type=”l”, solid line graph; type=”b”, all points are connected by solid lines; type=”o” solid line passes through all points ; Type=”h”, draw a vertical line from the point to the x-axis; type=”s”, draw a stepped curve; type=”n”, do not draw any points or curves.
Other graphics parameters
A. pch, specify the symbol used when drawing the point:
Insert picture description here
B.cex specifies the size of the symbol, cex is a numeric value that represents the multiple of the drawing symbol relative to the default size.
C.lty specifies the line type:
Insert picture description here
D. lwd specifies the line width, same as cex.
E. col specifies the drawing color. You can write a numeric value or a full name like "red". The function colors() can return the names of the left and right available colors. There are other functions for creating colors in R, such as rainbow(), heat.colors(), gray(), etc.
In the figure, the string
xlab=””, the content in the quotation marks is the name of the x-axis; ylab=””, the content in the quotation marks is the name of the y-axis; mean=””, the content in the quotation marks is the title of the figure, sub=””, the quotation marks The content is the description of the sub-picture.

Sometimes high-level mapping can't fully achieve the goal, and low-level functions are needed to supplement it. The graphics made by the low-level functions are based on the graphics drawn by the high-level graphics functions, adding new graphics.
Low-level drawing functions are: points(), lines(), text(), abline(), lens(), title(), axis(), etc.
The function
points() for adding points and lines is used to add points to an existing graph. The command points(x,y) is equivalent to plot(x,y).
lines(), the function is to add lines to the existing graph, the command lines(x,y), its function is equivalent to plot(x,y,type=”l”).

Mark the point with
text(), the function is to mark the graph, the command format is:
text(x,y,labels,...)
where x and y are data vectors, labels can be integers or strings , Labels=1:length(x) by default. For example, you need to draw a scatter plot of (x, y) and mark all points with numbers. The command is:
plot(x,y);text(x,y)
Add a straight line
function abline() to the graph. Add a straight line, the usage method has the following format:
A. abline(a,b) means to draw a straight line y=bx+a.
B. abline(h=y), which means to draw a horizontal straight line passing y.
C. abline(v=x), which means to draw a vertical straight line passing x.
Add a mark, description or other content to the figure. The
usage is:
title(main=””,sub=””,...), the main title is at the top of the figure, and the subtitle is at the bottom of the figure.
Add a mark, description or other content on the coordinate axis, the usage is:
axis(side,...), side means side, 1, 2, 3, 4 means that the content is placed on the bottom, left, top, and right respectively.
Add a legend to the map, the usage is:
lengend(location,title,...), location is the location of the designated legend, and title is the title of the legend.
eg

dose=c(20,30,40,45,60)
drugA=c(16,20,27,40,60)
drugB=c(15,18,25,31,40)
plot(dose,drugA,type="b",pch=15,lty=1,col="red",ylim=c(0,60),main="Drug A vs. Drug B",xlab="Drug Dosage",ylab="Drug Response")

Insert picture description here

lines(dose,drugB,type="b",pch=17,lty=2,col="blue")

Insert picture description here

abline(h=c(30),lwd=1.5,lty=2,col="gray")

Insert picture description here

legend("topleft",inset=0.05,title="Drug Type",c("A","B"),lty=c(1,2),pch=c(15,17),col=c("red","blue"))

Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46445293/article/details/104896016