代码抄书,rmd输出word,通过run可以输出图形,knit会报错,代码与报错如下
attach(mtcars)
library(sm)
#创建分组因子
cyl.f<-factor(cyl,levels = c(4,6,8),
labels =c("4 cylinder","6 cylinder","8 cylinder") )
#绘制密度图
sm.density.compare(mpg,cyl,xlab="Miles Per Gallon")
title(main = "MPG Distribution by Car Cylinders")
#通过鼠标点击添加
colfill<-c(2:(1+length(cyl.f)))
legend(locator(1),levels(cyl.f),fill = colfill)
detach(mtcars)