博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
one R chart example
阅读量:4482 次
发布时间:2019-06-08

本文共 3110 字,大约阅读时间需要 10 分钟。

R统计分析(72页)。

图示结果:

 

过程:

> #-- Create a scatterplot with marginal histograms --

> x <- pmin(3, pmax(-3, stats::rnorm(50))) # 取(-3,3)中的随机数50个
> y <- pmin(3, pmax(-3, stats::rnorm(50)))
> xhist <- hist(x, breaks = seq(-3, 3, 0.5), plot = FALSE) # 直方图向量,具体的变量值见后面
> yhist <- hist(y, breaks = seq(-3, 3, 0.5), plot = FALSE)
> top <- max(c(xhist$counts, yhist$counts))   #此时值17
> xrange <- c(-3, 3)   #x轴取值范围
> yrange <- c(-3, 3)
> layout(matrix(c(2,0,1,3), 2, 2, byrow = TRUE), c(3,1), c(1,3), TRUE)  #把画图区域分块
> layout.show(3)
>
> par(mar=c(3,3,1,1))

#mar  A numerical vector of the form c(bottom, left, top, right) which gives the number of lines of margin to be specified on the four sides of the plot. The default is c(5, 4, 4, 2) + 0.1.

> plot(x,y, xlim=xrange, ylim=yrange, xlab="", ylab="")
>
> par(mar=c(0, 3, 1, 1))
> barplot(xhist$counts, axes = FALSE, ylim = c(0, top), space = 0 )
>
> par(mar=c(3, 0, 1, 1))
> barplot(yhist$counts, axes = FALSE, xlim = c(0, top), space = 0, horiz = TRUE )
>
> x
 [1]  0.02243276 -0.18802935  0.96635157 -0.06337091 -0.05320779 -0.25764274 -0.25904247 -0.16897359  0.99286435 -0.55518188  1.13752121  1.56176444  0.14995988 -0.60777977
[15]  0.02268866 -0.15339282  0.41942717  1.23640912  1.45951744 -0.08922257 -0.36184747  0.54985445 -0.74640503  0.31641000 -0.18868209 -0.38435261  0.59866851  0.37183951
[29]  0.15795068  0.05646891 -0.98648389 -0.90242599 -0.12530699 -0.97079945  0.14046142  0.37242721  0.40159553 -1.27605505 -0.88641508 -0.19047387 -1.46677651 -0.70993679
[43] -0.47961001  1.29435831 -0.90633420 -1.11204818 -0.25549535 -0.10933170  0.78662451 -0.29346732
> y
 [1]  0.01929088  0.83942150 -2.29704677  0.99042037  0.42855322 -0.38710509  0.04268235 -0.94027175 -0.42339996  0.63979947 -0.96425531 -1.27256363  0.11811349  1.02663524
[15] -1.42605569 -0.78948625  0.40814836 -1.06689005  0.09741875  0.64487464 -0.70083433  0.77933314 -0.63003075 -1.21861028  0.98110932  1.75623956  1.47086212  0.47224524
[29]  0.31256526  0.96391536 -0.63679697 -0.26752053  1.85726370 -1.26925445  0.19747309  0.70264365 -0.88407886 -1.62868142 -0.39982539  1.40772579  1.14357730 -1.12897447
[43]  0.62227522  1.74595794 -0.73986816  0.92358474 -0.95305925 -0.72233704 -1.43089255 -0.47765949
> xhist
$breaks
 [1] -3.0 -2.5 -2.0 -1.5 -1.0 -0.5  0.0  0.5  1.0  1.5  2.0  2.5  3.0

$counts

 [1]  0  0  0  3  9 17 11  5  4  1  0  0

$intensities

 [1] 0.00 0.00 0.00 0.12 0.36 0.68 0.44 0.20 0.16 0.04 0.00 0.00

$density

 [1] 0.00 0.00 0.00 0.12 0.36 0.68 0.44 0.20 0.16 0.04 0.00 0.00

$mids

 [1] -2.75 -2.25 -1.75 -1.25 -0.75 -0.25  0.25  0.75  1.25  1.75  2.25  2.75

$xname

[1] "x"

$equidist

[1] TRUE

attr(,"class")

[1] "histogram"
> yhist
$breaks
 [1] -3.0 -2.5 -2.0 -1.5 -1.0 -0.5  0.0  0.5  1.0  1.5  2.0  2.5  3.0

$counts

 [1]  0  1  1  7 10  5  9 10  4  3  0  0

$intensities

 [1] 0.00 0.04 0.04 0.28 0.40 0.20 0.36 0.40 0.16 0.12 0.00 0.00

$density

 [1] 0.00 0.04 0.04 0.28 0.40 0.20 0.36 0.40 0.16 0.12 0.00 0.00

$mids

 [1] -2.75 -2.25 -1.75 -1.25 -0.75 -0.25  0.25  0.75  1.25  1.75  2.25  2.75

$xname

[1] "y"

$equidist

[1] TRUE

attr(,"class")

[1] "histogram"
> xrange
[1] -3  3
> yrange
[1] -3  3

转载于:https://www.cnblogs.com/bangemantou/archive/2012/12/26/2834715.html

你可能感兴趣的文章
解锁scott用户
查看>>
多态的理解
查看>>
AspNet Core 发布到Linux系统和发布IIS 注意项
查看>>
Windows添加.NET Framework 3.0 NetFx3 失败 - 状态为:0x800f0950
查看>>
隐藏显示终端的光标(shell echo,linux c printf)
查看>>
SQL Server 存储过程
查看>>
JSP 标准标签库(JSTL)(JSP Standard Tag Library)
查看>>
导入项目遇到的问题: Some projects cannot be imported because they already exist in the workspace....
查看>>
华为:字符集合
查看>>
用Okhttp框架登录之后的Cookie设置到webView中(转)
查看>>
Java_Activiti5_菜鸟也来学Activiti5工作流_之入门简单例子(一)
查看>>
elasticsearch 5.x 系列之二 线程池的设置
查看>>
Java入门系列:实例讲解ArrayList用法
查看>>
洛谷P1080 国王游戏【大数】【贪心】
查看>>
OpenMP编程的任务调度控制
查看>>
卡特兰(Catalan)数列
查看>>
设计模式(一)工厂模式Factory(创建型)
查看>>
Warshall算法
查看>>
Python之匿名函数
查看>>
PhoneGap 3.0 安装
查看>>