R IN ACTION SELF-TUTORIAL-24 boxplot箱图的绘制 2020-06-18

1、Basic concept and meaning of the plot

  1. In the simplest box plot the central rectangle spans the first quartile to the third quartile (the interquartile range or IQR). A segment inside the rectangle shows the median and "whiskers" above and below the box show the locations of the minimum and maximum.
    2)If either type of outlier is present the whisker on the appropriate side is taken to 1.5×IQR from the quartile (the "inner fence") rather than the max or min, and individual outlying data points are displayed as unfilled circles (for suspected outliers) or filled circles (for outliers). (The "outer fence" is 3×IQR from the quartile.)
    3)最终的结果为:


    image.png

2、说明:表达的结果有:
最小值(minimum) ;下四分位数(Q1);中位数(Med--也就是Q2)
上四分位数(Q3);最大值(maximum);平均值
四分位间距(interquartile range)={\displaystyle Q3-Q1} (即ΔQ)
在区间 Q3+1.5ΔQ, Q1-1.5ΔQ 之外的值被视为应忽略(farout)。
farout: 在图上不予显示,仅标注一个符号∇。
最大值区间: Q3+1.5ΔQ
最小值区间: Q1-1.5ΔQ


image.png

image.png

image.png

3、实现:

library(ggplot2)#导入绘图包  
library(readxl)#导入读xls的包

excel数据为:


image.png

读取数据:

test1 <- read_excel("C:/Users/Mr.R/Desktop/test1.xlsx",  sheet = "Sheet1")#读取表
test1#会看到以下表
image.png

作图:

boxplot(test1, col = c("green","yellow","purple"),names = c("Sample1","Sample2","Sample3"), xlab = "Sample names", ylab = "Values", main ="RASHIDIN's BOXPLOT")

结果为:


image.png

你可能感兴趣的:(R IN ACTION SELF-TUTORIAL-24 boxplot箱图的绘制 2020-06-18)