美文网首页R语言学习笔记
R语言学习笔记11-绘图篇

R语言学习笔记11-绘图篇

作者: RudyHe | 来源:发表于2015-12-05 20:06 被阅读143次
    - plot
        - plot(c(1,2,3),c(1,2,4))    # draw 3 points (1,1) (2,2) (3,4)
        - plot(c(-3,3),c(-1,5),type="n")    # draw a blank canvas, only axis no content
        - x<-c(1,2,3)
        - y<-c(1,3,8)
        - plot(x,y)
        - lmout<-lm(y~x)    # linear regression
        - abline(lmout)    # draw line
        - lines(c(1.5,2.5),c(3,3)) # draw line with 2 points
        - plot(x,y,type="l")    # draw broken line
        - hist(x)
        - x11()    # pop a window on linux
        - hist(y)    # draw y hist on new window
        - d1=density(testscores$Exam1,from=0,to=100)
        - d2=density(testscores$Exam2,from=0,to=100)
        - plot(d1,main="",xlab="")
        - lines(d2)
        - points(testscores$Exam1,testscores$Exam3,pch="+")    # mark point with +
        - par(bg="yellow")    # yellow background
        - text(2.5,4,"abc")    # place text on axis(2.5,4)
        - hist(c(12,5,13,25,16))
        - locator(1)    # give the exact axis on hist diagram once
        - text(locator(1),"nv=75")    # place the text on locator 1's position on diagram
        - text(2.5,4,"abc",cex=1.5)    # 1.5 times bigger than normal's
        - f<-function(x) return(1-exp(-x))
        - curve(f,0,2)    # draw curve, x starts from 0.2, else from 0 by default
        - polygon(c(1.2,1.4,1.4,1.2),c(0,0,f(1.3),f(1.3)),col="gray")    # x of 1.2 1.4 1.4 1.2
        - plot(testscores)
        - lines(lowess(testscores))    # smooth
        - curve((x^2+1)^0.5,0.5,add=T)    # draw curve on current canvas
        - pdf("d12.pdf')
        - dev.list()    # show devices
        - dev.cur()
            - pdf 3
        - dev.off()
    

    相关文章

      网友评论

        本文标题:R语言学习笔记11-绘图篇

        本文链接:https://www.haomeiwen.com/subject/tioshttx.html