##把绘图窗口分成2,2的四个小部分
op <- par(mfrow = c(2, 2))
##island包含师姐各个大陆的面积
hist(islands)
##展示了上述直方图的结构;str用来展示任意R对象的结构
utils::str(hist(islands, col = "gray", labels = TRUE))
##把面积开平方根然后再绘图,有12个条形柱?
hist(sqrt(islands), breaks = 12, col = "lightblue", border = "pink")
##-- For non-equidistant breaks, counts should NOT be graphed unscaled:
##非等距的分组的情况,下面的这个直方图
r <- hist(sqrt(islands), breaks = c(4*0:5, 10*3:5, 70, 100, 140),
col = "blue1")
##显示出,条形图上的数字,text用于向一个绘图中添加文字
text(r$mids, r$density, r$counts, adj = c(.5, -.5), col = "blue3")
##sapply对一个列表或者向量的部分使用函数;这里对r的第二三列使用函数sum
sapply(r[2:3], sum)##同apply,lapply等
##下面在算什么
sum(r$density * diff(r$breaks)) # == 1
##在画线,画边线?
lines(r, lty = 3, border = "purple") # -> lines.histogram(*)
有设置了一下四分屏幕
par(op)
require(utils) # for str##上面是直接用::来引用的
##str在命令行会返回很多有关图示的信息,虽然可以不用标在图上,一般包含留个变量的值
str(hist(islands, breaks = 12, plot = FALSE)) #-> 10 (~= 12) breaks
str(hist(islands, breaks = c(12,20,36,80,200,1000,17000), plot = FALSE))
hist(islands, breaks = c(12,20,36,80,200,1000,17000), freq = TRUE,
main = "WRONG histogram") # and warning
require(stats)
##设置产生随机数的种子为14
set.seed(14)
##产生一个 Chi-Squared(卡方?)分布
x <- rchisq(100, df = 4)
##检验分布,画出qq图
## Comparing data with a model distribution should be done with qqplot()!
qqplot(x, qchisq(ppoints(x), df = 4)); abline(0, 1, col = 2, lty = 2)
## if you really insist on using hist() ... :
##ylim有一个向量,包含轴的最小值最大值
hist(x, freq = FALSE, ylim = c(0, 0.2))
curve(dchisq(x, df = 4), col = 2, lty = 2, lwd = 2, add = TRUE)
##把绘图窗口分成2,2的四个小部分
op <- par(mfrow = c(2, 2)