Example Analysis of plot drawing in R language
What this article shares to you is the example analysis of plot drawing in R language. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Parameters in the drawing function:
Graphic element parameters:
Pch: used to display the coordinates of a point, either a character or an integer from 0 to 25. Such as: pch= "+", pch=1
Lty: line type. Such as: lty=2,lty=1
Lwd: line width. Such as: lwd=2
Col: color settings for points, lines, text, and filled areas. Col.axis, col.sub, and col.main correspond to axis dimensions, subtitles, and main title colors, respectively. Such as col=2, col.sub=2
Font: font settings. Same as above
Cex: character expansion rate, which represents the ratio of the expected character size (including drawing characters) to the default size.
The argument to the plot () function:
Xlim and ylim: denote the length of the x-axis and y-axis, for example: plot (passign, type= "l", xlim=c (0100)) means that the x-axis coordinates are from 0 to 0100.
Add=TRUE forces the function to run as a low-level drawing function, loading new graphic elements on the current graph (only suitable for some functions).
Axes=FALSE forbids the generation of axes | it is useful when you want to use the function axis () to draw personalized axes. The default value is axes=TRUE, which means the axis is generated.
Log:log= "x", log= "y", log= "xy" make the x axis, the y axis, or both logarithmic axes, which works for many graphs, but not all.
The type= parameter type= controls the type of output graphics, especially lines:
Type= "p" displays only dots (default)
Type= "l" displays lines
Type= "b" (simultaneously) displays dots and lines
Type= "o" overlays the dot on the line
Type= "h" draws a vertical line from point to zero axis (x axis) (high density (high-density))
Type= "s"
Type= "S" step chart. In the first form, the top of the vertical line matches the data points; in the second form, the bottom matches.
Type= "n" graphics are not displayed. However, the axis is still displayed (the default), and the coordinates are still set by data. This is very suitable for drawing later with low-level drawing functions.
Xlab=string
Ylab=string sets labels for the x and y axes. You can use these parameters to modify the default label. The default label is often the name of the object used in the advanced drawing function.
Legend (x, y, legend,...): adds a legend (legend) to a specific location in the current diagram. Identification characters, line formats, colors, etc., are all annotated by the tags in the character vector legend. Another parameter v that contains the corresponding value of the drawing units (a vector that is consistent with the length of the legend) must be given:
Legend (, fill=v)
Fill the color of the box
Legend (, col=v)
The color of a dot or line
Legend (, lty=v)
Line styl
Legend (, lwd=v)
Line width
Legend (, pch=v)
Identification character (character vector)
Example:
Plot (passign, type= "l", col=1, lwd=3, lty=1, xlim=c (0100))
Lines (psubmit, type= "l", col=2, lwd=3, lty=2)
Legend (50150, legend=c ("assignTo", "submitBy"), col=1:2, lwd=3, lty=c (1mem2))
The above is the example analysis of plot drawing in R language. The editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.