FIG box language R

FIG box through five drawn numbers summarize continuous variables, i.e., the minimum value, the lower quartile, median, quartile and maximum values of the distribution of continuous variables used to describe the
box can be displayed possible from FIG. group point (outside the range of values ± * IQR 1.5, IQR represent interquartile range, i.e., upper and lower quartile quartile) observation
# examples

boxplot(mtcars$mpg,main="Box plot",ylab="Miles per Gallon")
#使用boxplot.stats返回用于构建图形的统计量(即五数)
boxplot.stats(mtcars$mpg)

Here Insert Picture Description
Example 2, using parallel cross FIG box group
box plot shows a single variable may be variable or packet. Format
boxplot (formula, data = dataframe)
wherein formula is a formula, the formula is y ~ A sample, which will each category A categorical variables in parallel is generated box plots numeric variable y (simply is by grouping a, and then divided into y group showed good juxtaposed FIG box)
box plot parameters y ~ a * B was combinations of two categorical parameters a and B of all levels generated numeric variable y is zero
parameter varwidth = TRUE will cause its width is proportional to the square root of the sample size box of FIG
parameters notch = TRUE, the groove can be obtained containing box plot
direction parameter horizontal = TRUE axes may be reversed

#例子,研究四缸,六缸,8缸发动机对每加仑汽车行驶里程数的影响
boxplot(mtcars$mpg~mtcars$cyl,
        horizontal=TRUE,
        notch=TRUE,varwidth=TRUE,col=c("red","blue","green"),
        main="Car Mileage Date",
        xlab="Number of Cylinders",
        ylab = "Miles Per Gallon")

Here Insert Picture Description
Examples 2,2 Two box-shaped cross factor FIG
plurality of intersecting x-axis labels factors would be factors of each class such as cross-coupling factor A category c ( "a", "b ") two categories, cross category of factor B c (1,2) If the two classes do not deal with the case for x-axis labels c ( "a.1", "a.2 ", "b.1", "b.2")
but such a label can not be a good representation of the meaning of the label. So sometimes we need to re-set factor (ie modify the category label)

#重新设置因子是为了x轴刻度的标签,因为它是两个变量因子值的联结如果不设定就会变成(4.0,4.1,6.0,6.1,8.0,8.1)
#创建气缸数量的因子
mtcars$cyl.f <- factor(mtcars$cyl,levels=c(4,6,8),labels=c("4","6","8"))
#创建变速箱类型的因子
mtcars$am.f <- factor(mtcars$am,levels = c(0,1),labels=c("auto","standard"))
attach(mtcars)
boxplot(mpg~am.f*cyl.f,
        varwidth=TRUE,
        col=c("gold","darkgreen"),
        main="MPG Distribution by Auto Type",
        xlab="Auto Type",ylab="Miles Per Gallon")


Here Insert Picture Description
Examples 3, FIG violin
violin FIG box conjunction with FIG nuclear density map, the proportion of each part of the graphical representation of what percentage of the value in this region there is a
range of the black box is to the four quartiles quantile, thin black line represents shall
violin FIG via vioplot package vioplot () function draws
attention vioplot () separation function requires the drawing of a different set to a different variable and not as barplot () function as grouped themselves.

library(vioplot)
x1 <- mtcars$mpg[mtcars$cyl==4]
x2 <- mtcars$mpg[mtcars$cyl==6]
x3 <- mtcars$mpg[mtcars$cyl==8]
vioplot(x1,x2,x3,names = c("cyl4","cyl6","cyl8"),col="gold",
        main="Car Mileage Date",
        xlab="Number of Cylinders",
        ylab = "Miles Per Gallon")

Here Insert Picture Description
End Summary:
function creating box map with a boxplot ((), vioplot () , vioplot () function is created for violin FIG., It is a combination of box plots and nuclear density map.
Boxplot () function can produce a single box FIG, can also be produced plural sets box plot (by packet)
Boxplot () function parameters are used varwidth, notch, horizontal

Published 39 original articles · won praise 11 · views 10000 +

Guess you like

Origin blog.csdn.net/weixin_42712867/article/details/96422023