zoukankan      html  css  js  c++  java
  • 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()

     





     
  • 相关阅读:
    [GDKOI2010] 圈地计划(网络流)
    jzoj3454 表白(love)解题报告(01分数规划+DP)
    数论之卢卡斯定理
    POJ1180 Batch Scheduling 解题报告(斜率优化)
    BZOJ 球形空间产生器 解题报告(高斯消元)
    你是怎么封装一个view的
    沙盒目录结构是怎样的?各自用于那些场景?
    这个写法会出什么问题: @property (copy) NSMutableArray *array;
    怎么用 copy 关键字?
    @property后面可以有哪些修饰符?
  • 原文地址:https://www.cnblogs.com/wangshenwen/p/3235858.html
Copyright © 2011-2022 走看看