1. 程式人生 > >R語言繪製 盒型圖 boxplot

R語言繪製 盒型圖 boxplot

程式碼及結果如下:

boxplot(count ~ spray, data = InsectSprays, col = “lightgray”)

title(“統計諮詢 微信:pencion”)
這裡寫圖片描述

boxplot(count ~ spray, data = InsectSprays, notch = TRUE, add = TRUE, col = “blue”)

title(“統計諮詢 微信:pencion”)

這裡寫圖片描述

boxplot(decrease ~ treatment, data = OrchardSprays, log = “y”, col = “bisque”)

title(“統計諮詢 微信:pencion”)

這裡寫圖片描述

rb <- boxplot(decrease ~ treatment, data = OrchardSprays, col = “bisque”)

title(“統計諮詢 微信:pencion”)

mn.t <- tapply(OrchardSpraysdecrease,OrchardSpraystreatment, mean)

sd.t <- tapply(OrchardSpraysdecrease,OrchardSpraystreatment, sd)

xi <- 0.3 + seq(rb$n)

points(xi, mn.t, col = “orange”, pch = 18)

arrows(xi, mn.t - sd.t, xi, mn.t + sd.t, code = 3, col = “pink”, angle = 75, length = .1)

這裡寫圖片描述

mat <- cbind(Uni05 = (1:100)/21, Norm = rnorm(100),

5T = rt(100, df = 5), Gam2 = rgamma(100, shape = 2))

boxplot(mat) # directly, calling boxplot.matrix()

title(“統計諮詢 微信:pencion”)

這裡寫圖片描述

df. <- as.data.frame(mat)

par(las = 1)

boxplot(df., main = “統計諮詢 微信:pencion”, horizontal = TRUE)

這裡寫圖片描述

boxplot(len ~ dose, data = ToothGrowth,

boxwex = 0.25, at = 1:3 - 0.2,

subset = supp == “VC”, col = “yellow”,

main = “統計諮詢 微信:pencion”,

xlab = “Vitamin C dose mg”,

ylab = “tooth length”,

xlim = c(0.5, 3.5), ylim = c(0, 35), yaxs = “i”)
這裡寫圖片描述

boxplot(len ~ dose, data = ToothGrowth, add = TRUE,

boxwex = 0.25, at = 1:3 + 0.2,

subset = supp == “OJ”, col = “orange”)
這裡寫圖片描述

legend(2, 9, c(“Ascorbic acid”, “Orange juice”),

fill = c(“yellow”, “orange”))

這裡寫圖片描述

boxplot(len ~ dose:supp, data = ToothGrowth,

boxwex = 0.5, col = c(“orange”, “yellow”),

main = “統計諮詢 微信:pencion”,

xlab = “Vitamin C dose mg”, ylab = “tooth length”,

sep = “:”, lex.order = TRUE, ylim = c(0, 35), yaxs = “i”)

這裡寫圖片描述

結束,歡迎交流諮詢。