R language 3.13 drawing

  • The plot function
    plot() can draw scatter plots, graphs, etc. of data.
    plot(x,y), where x and y are vectors, generate a scatter plot of x and y.
    plot(x), where x is a time series, generate time series graphics. If x is a vector, a scatter plot of x with respect to the subscript is generated; if x is a complex vector, a scatter plot of the real and imaginary parts of the complex number is drawn.
    plot(f)
    plot(f,y)
    where f is a factor and y is a numeric vector. The first format generates a histogram of f, and the second format generates a box plot of y with respect to the level of f.
    For example, using four different formulations of materials A1, A2, A3, A4 to produce components, the measured life is shown in the following table:
    Insert picture description here
    Draw box plots of the life of four different formulations of materials.
y=c(1600, 1610, 1650, 1680, 1700, 1700, 1780, 1500, 1640, 
     1400, 1700, 1750, 1640, 1550, 1600, 1620, 1640, 1600, 
     1740, 1800, 1510, 1520, 1530, 1570, 1640, 1600)
f=factor(c(rep(1,7),rep(2,5), rep(3,8), rep(4,6))) 
plot(f,y)

Insert picture description here
f=factor(c(rep(1,7),rep(2,5), rep(3,8), rep(4,6))) (There are 7 factors for factor 1, 5 factors for factor 2, and factor 3 There are 8 and factor 4 has 6)

  • The pairs function
    pairs(x), when x is a matrix or a data frame, a scatter plot about each column of the matrix can be drawn.
  • qqnorm() checks whether the sample obeys a normal distribution. qqline() adds a straight line to the graph to draw a QQ scatter plot.
  • hist(), draw a histogram.
  • dotchart(x), construct a dot chart of data x. For example: R has its own data VADEaths, which is the death rate of the population of Virginia in 1940.
dotchart(VADeaths)
dotchart(t(VADeaths))

Insert picture description here
Insert picture description here

  • image(x,y,z), countour(x,y,z), persp(x,y,z)
    where x and y are numeric vectors, the number of rows in z is the dimension of x, and the number of columns in z Is the dimension of y. Image() draws three-dimensional graphics, contour() draws contours of three-dimensional graphics, and persp() draws surface curves of three-dimensional graphics.
    Example: The height (unit: m) of some places in a mountainous area is measured. As shown below, try to make a landform map and contour map of the mountainous area.
x=seq(0,2800, 400)
y=seq(0,2400,400)
z=scan()#扫描数据
1: 1180 1320 1450 1420 1400 1300  700  900
9: 1230 1390 1500 1500 1400  900 1100 1060
17: 1270 1500 1200 1100 1350 1450 1200 1150
25: 1370 1500 1200 1100 1550 1600 1550 1380
33: 1460 1500 1550 1600 1550 1600 1600 1600
41: 1450 1480 1500 1550 1510 1430 1300 1200
49: 1430 1450 1470 1320 1280 1200 1080  940
Z=matrix(z, nrow=8)
image(x, y, Z)
contour(x, y, Z, levels = seq(min(z), max(z), by = 80))
persp(x, y, Z)

Insert picture description here
Insert picture description here
Insert picture description here
We can see that the graph has two shortcomings: one is too rough, the reason is that the amount of data is too small, if the amount of data is slightly larger, the graphics quality will be greatly improved; the second is the observation of the three-dimensional map The angle is not ideal, because only the default value states of various parameters in the function are used. If the value of some parameters is changed, the viewing angle of the graph will also change.

persp(x, y, Z)

Insert picture description here

persp(x, y, Z,theta=30,phi=45,expand=0.7)

Insert picture description here
Insert picture description here

Guess you like

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