rm(list=ls())
options(stringsAsFactors = FALSE)
# 初次使用需要安装
install.packages("vioplot")
rm(list = ls())
library(vioplot)
#使用内置数据
mtcars
pdf("vioplot2.pdf")#打开画板
#设置坐标轴
par(las=1,bty="l")
#las。只能是0,1,2,3中的某一个值,用于表示刻度值的方向。0表示总是平行于坐标轴;1表示总是水平方向;2表示总是垂直于坐标轴;3表示总是垂直方向。
#bty。该参数值为字符串型,用于限定图形的边框类型。如果bty的值为"o"(默认值)、"l"、"7"、"c"、"u"或者"]"中的任意一个,对应的边框类型就和该字母的形状相似。如果bty的值为"n",表示无边框。
#以cyl=6和8的mag为例
x1 <- mtcars$mpg[mtcars$cyl==6]
x2 <- mtcars$mpg[mtcars$cyl==8]
vioplot(x1,x2,
names = c("6 cyl","8 cyl"),
col = "#00CD00")
dev.off()

参考 木舟笔记
网友评论