R1 Lecture 07 Class Notes

R1 Lecture 07b Class Notes

By YU,Xiang

Apr 14 2015

常用统计图形

直方图 条形图

折线图 散点图

饼图

箱线图

barplot

Description:

     Creates a bar plot with vertical or horizontal bars.

Usage:

     barplot(height, ...)

     ## Default S3 method:
     barplot(height, width = 1, space = NULL,
             names.arg = NULL, legend.text = NULL, beside = FALSE,
             horiz = FALSE, density = NULL, angle = 45,
             col = NULL, border = par("fg"),
             main = NULL, sub = NULL, xlab = NULL, ylab = NULL,
             xlim = NULL, ylim = NULL, xpd = TRUE, log = "",
             axes = TRUE, axisnames = TRUE,
             cex.axis = par("cex.axis"), cex.names = par("cex.axis"),
             inside = TRUE, plot = TRUE, axis.lty = 0, offset = 0,
             add = FALSE, args.legend = NULL, ...)
# height is a vector
par(mfrow=c(2,2))
barplot(1:8,col=1:8,main="barplot(1:8,col=1:8)")
# height is a matrix
mg <- table(mtcars$gear,mtcars$carb)
barplot(mg,col=1:3,main="barplot(mg,col=1:3)")
# besides and legend
barplot(mg,col=1:3,beside=TRUE,legend.text=TRUE,main="beside=TRUE,legend.text=TRUE")
barplot(mg,col=1:3,horiz=TRUE,width=1.5,main="horiz=TRUE,width=1.5")

这里写图片描述

histogram

Description:

     The generic function ‘hist’ computes a histogram of the given data
     values.  If ‘plot = TRUE’, the resulting object of class
     ‘"histogram"’ is plotted by ‘plot.histogram’, before it is
     returned.

Usage:

     hist(x, ...)

     ## Default S3 method:
     hist(x, breaks = "Sturges",
          freq = NULL, probability = !freq,
          include.lowest = TRUE, right = TRUE,
          density = NULL, angle = 45, col = NULL, border = NULL,
          main = paste("Histogram of" , xname),
          xlim = range(breaks), ylim = NULL,
          xlab = xname, ylab,
          axes = TRUE, plot = TRUE, labels = FALSE,
          nclass = NULL, warn.unused = TRUE, ...)
par(mfrow=c(2,2))
hist(mtcars$mpg,
    main="hist(mtcars$mpg)")
# freqency or probability
hist(mtcars$mpg,freq=FALSE,
    main="freq=FALSE")

# the breaks, colors and borders
hist(mtcars$mpg,breaks=6,col=1,
    main="breaks=6,col=1")
hist(mtcars$mpg,breaks=c(9,13,18,20,25,35),col=3,border=FALSE,
    main="breaks=c(9,13,18,20,25,35),col=3,border=FALSE")

这里写图片描述

pie

Description:

     Draw a pie chart.

Usage:

     pie(x, labels = names(x), edges = 200, radius = 0.8,
         clockwise = FALSE, init.angle = if(clockwise) 90 else 0,
         density = NULL, angle = 45, col = NULL, border = NULL,
         lty = NULL, main = NULL, ...)
args(pie)
## function (x, labels = names(x), edges = 200, radius = 0.8, clockwise = FALSE, 
##     init.angle = if (clockwise) 90 else 0, density = NULL, angle = 45, 
##     col = NULL, border = NULL, lty = NULL, main = NULL, ...) 
## NULL
par(mfrow=c(1,3))
pie(table(mtcars$carb),
    main="pie(table(mtcars$carb))")
# the radius and colors
pie(table(mtcars$carb),col=1:6,radius=1,
    main="col=1:6,radius=1")
# the labels
carb_name <- paste("gear =",names(table(mtcars$gear)))
pie(table(mtcars$gear),col=1:3,labels=carb_name,
    main="col=1:3,labels=carb_name")

这里写图片描述

boxplot

Description:

     Produce box-and-whisker plot(s) of the given (grouped) values.

Usage:

     boxplot(x, ...)

     ## S3 method for class 'formula'
     boxplot(formula, data = NULL, ..., subset, na.action = NULL)

     ## Default S3 method:
     boxplot(x, ..., range = 1.5, width = NULL, varwidth = FALSE,
             notch = FALSE, outline = TRUE, names, plot = TRUE,
             border = par("fg"), col = NULL, log = "",
             pars = list(boxwex = 0.8, staplewex = 0.5, outwex = 0.5),
             horizontal = FALSE, add = FALSE, at = NULL)

这里写图片描述

par(mfcol=c(2,2))
# single box
boxplot(mtcars$mpg,main="boxplot(mtcars$mpg)")
# horizontal box
boxplot(mtcars$mpg,horizontal=TRUE,main="horizontal=TRUE")
# multiple boxes generated from a formula
boxplot(mpg~cyl,mtcars,col=1:3,main="mpg~cyl,col=1:3")
# varwidth=TRUE
boxplot(mpg~cyl,mtcars,col=1:3,varwidth=TRUE,main="varwidth=TRUE")

这里写图片描述

第七周作业

理解 hist 和 barplot 中各种参数的作用,用恰当的图形,表现出不同参数(hist和barplot分别至少6个)的作用

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值