。小提琴图是箱线图与核密度图的结合。你可以使用vioplot包中的vioplot()函数绘制它。请在第一
次使用之前安装vioplot包
vioplot()函数的使用格式为:
vioplot(x1, x2, ... , names=, col=)
其中x1, x2, …表示要绘制的一个或多个数值向量(将为每个向量绘制一幅小提琴图)。参数
names是小提琴图中标签的字符向量,而col是一个为每幅小提琴图指定颜色的向量。
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("4 cyl", "6 cyl", "8 cyl"),
col="gold")
title("Violin Plots of Miles Per Gallon", ylab="Miles Per Gallon",
xlab="Number of Cylinders")