• Chapter 06—Basic graphs


    三. 柱状图(Histogram)

    1. hist():画柱状图

    ·breaks(可选项):控制柱状图的小柱子的条数;

    ·freq=FALSE:基于概率(probability),而非频率(frequencies),绘制图形。

    ·还可以有其他参数,如:xlab,ylab,main,col,lwd...

    2. lines():在已有图形上添加线条。

    3. box():给已有图形添加一个框。

    4. rug()

    5. diff()

    6.box()

    例07:

    > par(mfrow=c(2,2))
    > hist(mtcars$mpg)
    >
    > hist(mtcars$mpg,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram,rug plot,density curve")
    >

    >
    hist(mtcars$mpg,freq=FALSE,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram,rug plot,density curve")
    > rug(jitter(mtcars$mpg))
    > lines(density(mtcars$mpg),col="blue",lwd=2)

    > x<-mtcars$mpg
    > h<-hist(x,breaks=12,col="red",xlab="Miles Per Gallon",main="Histogram with normal curve and box")
    > xfit<-seq(min(x),max(x),length=40)
    > yfit<-dnorm(xfit,mean=mean(x),sd=sd(x))
    > yfit<-yfit*diff(h$mids[1:2]*length(x))
    > lines(xfit,yfit,col="blue",lwd=2)
    > box()

    四. 中心密度曲线(kernel dentity plots)

    plot(dentity(x)):画中心密度曲线

    sm包中的函数sm.density.compare()函数:在同一个图中,画出多组中心密度曲线。

     例08:

    > 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")

     

     例09:

    > install.packages("sm")
    trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.0/sm_2.2-5.3.zip'
    Content type 'application/zip' length 445006 bytes (434 Kb)
    opened URL
    downloaded 434 Kb
    
    package ‘sm’ successfully unpacked and MD5 sums checked
    
    The downloaded binary packages are in
    	C:Usersseven-wangAppDataLocalTempRtmpYfr9xmdownloaded_packages
    > library(sm)
    Package `sm', version 2.2-5: type help(sm) for summary information
    > par(lwd=2)
    > attach(mtcars)
    > cyl.f<-factor(cyl,levels=c(4,6,8),labels=c("4 cylinder","6 cylinder","8 ylinder"))
    > 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()

     





     
  • 相关阅读:
    结合使用allure当中的方法 让用例执行结果内 显示详细描述信息
    pytest-repeat插件,指定用例重复运行、重复运行次数
    pytest-xdist 分布式执行用例
    token
    使用pytest-ordering 来自定义用例执行顺序
    用例编写规则、命令行执行用例、用例执行的先后顺序
    python 中的doctest单元测试框架
    pytest 对用例mark标记分类(且用例也可按照分类来执行)
    学习webpack基本配置(一)
    (剑指offer)数组中出现次数超过一半的数字
  • 原文地址:https://www.cnblogs.com/wangshenwen/p/3235858.html
Copyright © 2020-2023  润新知