In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the role of par() function in R language is, the quality of the article content is high, so Xiaobian shares it with you as a reference, I hope you have a certain understanding of relevant knowledge after reading this article.
Setting graphic parameters in R--Detailed explanation of par() function
R has a very powerful drawing function, we can use a few simple lines of code to draw a variety of graphics, but sometimes the default graphics settings do not meet our needs, and even encounter a variety of small problems: such as coordinate axis or title out of bounds, or legend description size or position blocked graphics, and sometimes even the default color does not meet our needs. How to adjust? This uses the "powerful" function par(). We can adjust our graph by setting the parameters of par(), and this blog post summarizes the parameters of par().
The par() function is used in the following format:
par(..., no.readonly = FALSE)
Among them... Represents all parameters of the form tag=value. These parameters are described in detail below. When the parameter no.readonly=TRUE, par() allows only this parameter and returns the parameter values for each parameter in the current drawing device.
Each graphics device has its own drawing parameters. If a graphics device is not currently open, the par() function automatically opens a new graphics device before setting parameters.
As mentioned earlier, entering par() or par(no.readonly=TRUE) directly in the R editor can obtain the current drawing parameters.
Parameters in the function par() can be divided into three categories:
It can only be read, not set. include parameters cin, cra, csi, cxy, din.
It can only be set via the par() function. Included parameters:
"ask",
"fig", "fin",
"lheight",
"mai", "mar", "mex", "mfcol", "mfrow", "mfg",
"new",
"oma", "omd", "omi",
"pin", "plt", "ps", "pty",
"usr",
"xlog", "ylog"
In addition to par(), the remaining parameters can also be set by various advanced drawing functions, such as plot, points, lines, abline, title, text, axis, image, box, contour, rect, arrows, etc.
When a parameter value is set, the default returns the value of the parameter before it was set. We can usually save these values in some variables. These historical values can be used to restore settings after the operation (although this is not recommended because it may cause some parameter value conflicts). For example:
> x x
$bg
[1] "transparent"
> plot(1:10)
> par(x)
> plot(1:100)
Next, I will give a general explanation of the meaning of each parameter, and I will use some simple code as an example.
adj。This parameter value is used to set the alignment direction of strings in text, mtext, title. 0 for left alignment, 0.5 (default) for center, and 1 for right alignment (note that any value in the interval [0,1] is valid for the parameter adj, and in most graphics devices, values outside the interval are valid). Note that the value of the parameter adj in the function text can be reoriented in a form similar to adj=c(x,y). But in text the value of this parameter affects the tag of the point, and in the case of the functions mtext and title the value of the parameter adj affects the entire image or device area.
> par(mfrow=c(1,2))
> plot(1:4)
> title("plot(1:4)",adj=0)
> plot(1:4)
> title("plot(1:4)",adj=1)
ann。If ann=FALSE, then the high-level plot function calls the function plot.default to make no comment on the axis name or the overall image name. The default value is TRUE.
> plot(1:4,ann=FALSE,main='plot(1:4,ann=FALSE)')#Although the value of the parameter main is specified, it is still not displayed in the image
> plot(1:4,ann=TRUE,main='plot(1:4,ann=FALSE)')
ask, logical value. If TRUE (and the current R session is interactive), the user is asked for confirmation before drawing the new image. The same applies to grid and lattice extensions, and may even apply to devices with no screen output (but it may not work).
bg。Use to set the background color of the drawing area. When called by the par() function, the parameter new=FALSE is also set. For many devices, the initial value of this parameter is the background color value of the device, otherwise it is generally "white". It should be noted that some graph functions such as plot.default and points also have parameters called bg, but the meaning is different.
bty。This parameter value is a string type and is used to define the border type of the drawing. If bty has any of the values "o"(default),"l,""7,""c,""u," or "]," the corresponding border type resembles the shape of the letter. If bty has a value of "n," it means no border.
cex。Use to indicate how much to magnify default drawing text and symbols. Note that some plotting functions such as plot.default also have a parameter with the same name, but this time it indicates how many times it is magnified on the basis of the parameter cex of the function par(). In addition, there are functions such as points that accept a numerical vector as a parameter.
cex.axis。Indicates the magnification of the axis scale value font at the current cex setting.
cex.lab。Indicates the magnification of the axis name font at the current cex setting.
cex.main。Indicates the magnification of the main title font at the current cex setting.
cex.sub。Indicates the magnification of the subtitle font at the current cex setting.
cin。This is a read-only parameter and cannot be modified. Returns the font size in inches in the form (width,height). This is the same as cra, but in different units of measurement.
col。Used to set the default drawing color (admittedly this is a very special parameter, later will summarize the blog post dedicated to how to set the color R set graphics parameters-function par() detailed explanation).
col.axis。Color of axis scale value, default is "black". Such as code:
> par(cex.axis=3,col.axis="red")
> plot(1:4)
col.lab。Color of axis name, default is "black".
col.main。The color of the main title defaults to "black."
col.sub。The color of the subtitle defaults to "black."
cra。See description of parameter cin.
crt。The value of this parameter is a numeric value representing the number of degrees of rotation of a single character, preferably a multiple of 90. The srt parameter differs from the srt parameter in that the srt parameter rotates the entire string.
csi。Read-only parameter that returns the default character height in inches.
cxy。Read-only parameter that returns the default character width and height in the form (width,height), where par("cxy")=par("cin")/par("pin").
din。Read-only parameter representing the size specification of the drawing device, returned in inches as (width,height).
family。The font type of the characters in the drawing. The maximum length is 200 bytes. The default value is "", which means the default font for the drawing device is used.
fg。The color of the prominent position in the graph (such as coordinate axis, tick mark, border, etc.) is generally "black" by default.
fig。A numeric vector of the form c(x1, x2, y1, y2), used to set the area occupied by the current graphic in the drawing device, note that x1 plot(1:3) needs to be satisfied.
> par(fig=c(0.5,1,0.5,1))
> plot(1:3)
> par(fig=c(0,0.5,0,0.5),new=TRUE)
> plot(1:3)
fin。The size specification of the current drawing area in inches in the form (width,height). If you change the value of this parameter, the default is to start a new drawing device.
font。Used to set which font to use, is an integer. 1 for plain text (default), 2 for bold, 3 for italics, 4 for black italics. Under Adobe character encoding, 5 is also possible.
font.axis。The font of the axis scale value.
font.lab。Font for axis names.
font.main。The font of the main title.
font.sub。The font of the subtitle.
lab。A numeric vector of the form c(x,y,len) used to specify the name of the coordinate axis. The values x and y are used to set the number of tick marks on the x and y axes, while len sets the length of the tick marks (currently this value in R has no effect).
las。It can only be one of 0, 1, 2, 3, and is used to indicate the direction of the scale value. 0 means always parallel to the coordinate axis;1 means always horizontal;2 means always perpendicular to the coordinate axis;3 means always vertical.
lend。The endpoint style of the segment. The parameter value can be an integer or a string. A parameter value of 0 or "round" indicates that the endpoint style is rounded (default); 1 or "butt" indicates that the endpoint is truncated directly; 2 or "square" indicates that the endpoint is extended. Such as code:
> plot(1:8,type="n",ylim=c(1,6))
> x0 y0 x1 y1 segments(x0,y0,x1,y1)
> x0 y0 x1 y1 segments(x0,y0,x1,y0,lwd=10,col="red")
#modify parameter lend=1
> y0 y1 segments(x0,y0,x1,y0,lwd=10,col="green",lend=1)
#modify parameter lend=2
> y0 y1 x0 x1 segments(x0,y0,x1,y0,lwd=10,col="blue",lend=2)
lty。Line type. Parameters can be integers (0 is empty, 1 is solid (default), 2 is dashed, 3 is dotted, 4, 5, 6, etc.) or strings (one-to-one with integers, such as "blank,""solid,""dashed,""dotted,""dotdash,""longdash," or "twodash").
lwd。Line width. Must be an integer, default is 1. The specific implementation depends on the device, and some drawing devices do not support line widths less than 1.
mfcol,mrow。Used to set the layout of the graphics device (simply to divide the current graphics device into nr*nc sub-devices), the parameter form is c(nr, nc). The drawing order of the subgraphs is determined by column or row, depending on whether mfcol or mfrow is specified by the Yes parameter. To achieve the same functionality, you can use the layout or split.screen.
mgp。Sets the title, axis name, and distance from the drawing border. The default value is c(3,1,0), where the first value affects the title.
new。Logical value, default is FALSE. If set to TRUE, the next advanced drawing command does not clear the current drawing device.
oma。The parameter c(bottom, left, top, right) is used to set the outer boundary.
omi。Same as oma, except in inches.
pch。Represents the shape of a point, and its value can be numeric (a number between 0 and 25) or character. 1 for circle, 2 for triangle, 3 for plus sign. When the value of pch is character type, then the point is represented by that character.
pin。The current dimension of the form c(width,height) in inches.
plt。The form c(x1, x2, y1, y2) sets the current drawing area.
pty。A character-type parameter that indicates the shape of the current drawing area, with "s" generating a square area and "m" generating the largest drawing area.
srt。String rotation degrees, only function text is supported.
tck。The length of the tick mark, a fraction less than or equal to, that represents a portion of the height or width of the drawing area, whichever is smaller. If tck=1, gridlines are drawn. The default value is NA (equivalent to tcl=-0.5).
tcl。It can also be used to set the length of the tick marks, but the units are different from tck. Its default value is-0.5.
usr。A vector of the form c(x1, x2, y1, y2) representing the range of coordinate values of the current drawing area: c(xleft, xright, ybottom, ytop). If the logarithmic scale of is used (e.g. par("xlog")=TRUE), then the x-axis representation range is 10^par("usr")[1:2], and the y-axis representation range can also be obtained.
xaxp。A vector of the form c(x1, x2, n) representing the interval of tick marks on the x axis and the number of tick marks in the interval when par("xlog")=false. If par("xlog")=TRUE, the situation is slightly more complicated: if the range is small, then n is a negative number and the distribution of tick marks is similar to normal (without logarithmic transformation); if n takes one of 1, 2, and 3, c(x1,x2)=10^par("usr")[1:2](and par("usr") is the value returned if par("xlog")=TRUE). The explanation is as follows:
n=1, draw a tick mark at the coordinate value 10^j (j is an integer).
n=2, draw a tick mark at the coordinate value k*(10^j), where k is 1 or 5.
n=3, draw a tick mark at the coordinate value k*(10^j), where k is 1, 2, or 5.
yaxp。Similar to xaxp, it indicates the interval of tick marks on the y axis and the number of tick marks in the interval.
xaxs。The spacing setting method of coordinate axis x. Values range from "r", "i", "e", "s", "d". In general, the calculation is determined by the numerical range of xlim (if xlim is specified). "r"(regular) first extends the range by 4% at each end, and then sets coordinate values in the extended range;"i"(internal) sets coordinate values directly in the original range;"s"(standard) and "e"(extended);"d"(direct) are not currently supported.
yaxs。Similar to xaxs, spacing is set on the y axis.
xaxt。The type of scale value used to set the x axis, which is a character. "n" means no tick values and tick marks are drawn;"s" means draw, default value.
yaxt。Similar to Xaxt.
xlog。A logical value. If TRUE, it means logarithmic axis for x axis, default is FALSE.
ylog。Similar to xlog.
What is the role of the par() function in the R language is shared here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.