> par(mfrow=c(2, 1))
> d <- density(mtcars$mpg)
> 
> plot(d)
> 
> d <- density(mtcars$mpg)
> plot(d, main="kernel density of miles per gallon")
> polygon(d, col="red", border="blue")
> rug(mtcars$mpg, col="brown")
> 

R语言实战 - 基本图形(4)- 核密度图

> par(lwd=2)
> library(sm)
> attach(mtcars)
> 
> 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(levels(cyl.f))))
> legend(locator(1), levels(cyl.f), fill=colfill)
> 
> detach(mtcars)
> 

R语言实战 - 基本图形(4)- 核密度图

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2021-11-20
  • 2021-08-05
  • 2021-12-05
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-23
  • 2022-12-23
  • 2021-04-26
  • 2022-02-08
  • 2021-12-23
相关资源
相似解决方案