使用coplot()绘制多元图
> set.seed(1 ); x <- sample(c(1:50),10)
> set.seed(2); y <- sample(c(1:50),10)> f <- as.factor(c(rep('a',3),rep('b',5),rep('c',2)))> x[1] 14 19 28 43 10 41 42 29 27 3
> y[1] 10 35 28 8 44 43 6 36 20 23
> f[1] a a a b b b b b c c
Levels: a b c> coplot(y ~ x | f)
图的顺序:
下左图对应数据 :
a,a,a
10,14; 35,19; 28,28;下右对应数据 :
b,b,b,b,b
8,43; 44,10; 43,41; 6,42; 36,29;上左对应数据 :
c,c
20,27; 23,3;
当factor有4个水平(level)时, 绘制4幅图 :
> f <- as.factor(c(rep('a',3),rep('b',5),rep('c',1),rep('d',1)))
> f[1] a a a b b b b b c d
Levels: a b c d
> coplot(y ~ x | f)
> x <- 1:12
> y <- 100:111
> z <- 300:311
> x[1] 1 2 3 4 5 6 7 8 9 10 11 12
> y[1] 100 101 102 103 104 105 106 107 108 109 110 111
> z[1] 300 301 302 303 304 305 306 307 308 309 310 311
> coplot(y ~ x | z)
> mtcars$wt[1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070
[13] 3.730 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840
[25] 3.845 1.935 2.140 1.513 3.170 2.770 3.570 2.780
> mtcars$mpg[1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4
[16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7
[31] 15.0 21.4
> as.factor(mtcars$cyl)[1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4
Levels: 4 6 8coplot(mtcars$wt ~ mtcars$mpg | as.factor(mtcars$cyl), main="", xlab="", ylab="", pch=19)
> as.factor(mtcars$vs)[1] 0 0 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1
Levels: 0 1coplot(mtcars$wt ~ mtcars$mpg | as.factor(mtcars$cyl) * as.factor(mtcars$vs), main="", xlab="", ylab="", pch=19)
coplot package:graphics R DocumentationConditioning PlotsDescription:This function produces two variants of the *co*nditioning plotsdiscussed in the reference below.Usage:coplot(formula, data, given.values, panel = points, rows, columns,show.given = TRUE, col = par("fg"), pch = par("pch"),bar.bg = c(num = gray(0.8), fac = gray(0.95)),xlab = c(x.name, paste("Given :", a.name)),ylab = c(y.name, paste("Given :", b.name)),subscripts = FALSE,axlabels = function(f) abbreviate(levels(f)),number = 6, overlap = 0.5, xlim, ylim, ...)co.intervals(x, number = 6, overlap = 0.5)Arguments:formula: a formula describing the form of conditioning plot. Aformula of the form ‘y ~ x | a’ indicates that plots of ‘y’versus ‘x’ should be produced conditional on the variable‘a’. A formula of the form ‘y ~ x| a * b’ indicates thatplots of ‘y’ versus ‘x’ should be produced conditional on thetwo variables ‘a’ and ‘b’.All three or four variables may be either numeric or factors.When ‘x’ or ‘y’ are factors, the result is almost as if‘as.numeric()’ was applied, whereas for factor ‘a’ or ‘b’,the conditioning (and its graphics if ‘show.given’ is true)are adapted.data: a data frame containing values for any variables in theformula. By default the environment where ‘coplot’ wascalled from is used.given.values: a value or list of two values which determine how theconditioning on ‘a’ and ‘b’ is to take place.When there is no ‘b’ (i.e., conditioning only on ‘a’),usually this is a matrix with two columns each row of whichgives an interval, to be conditioned on, but is can also be asingle vector of numbers or a set of factor levels (if thevariable being conditioned on is a factor). In this case (no‘b’), the result of ‘co.intervals’ can be used directly as‘given.values’ argument.panel: a ‘function(x, y, col, pch, ...)’ which gives the action tobe carried out in each panel of the display. The default is‘points’.rows: the panels of the plot are laid out in a ‘rows’ by ‘columns’array. ‘rows’ gives the number of rows in the array.columns: the number of columns in the panel layout array.show.given: logical (possibly of length 2 for 2 conditioningvariables): should conditioning plots be shown for thecorresponding conditioning variables (default ‘TRUE’).col: a vector of colors to be used to plot the points. If tooshort, the values are recycled.pch: a vector of plotting symbols or characters. If too short,the values are recycled.bar.bg: a named vector with components ‘"num"’ and ‘"fac"’ giving thebackground colors for the (shingle) bars, for *num*eric and*fac*tor conditioning variables respectively.xlab: character; labels to use for the x axis and the firstconditioning variable. If only one label is given, it isused for the x axis and the default label is used for theconditioning variable.ylab: character; labels to use for the y axis and any secondconditioning variable.subscripts: logical: if true the panel function is given an additional(third) argument ‘subscripts’ giving the subscripts of thedata passed to that panel.axlabels: function for creating axis (tick) labels when x or y arefactors.number: integer; the number of conditioning intervals, for a and b,possibly of length 2. It is only used if the correspondingconditioning variable is not a ‘factor’.overlap: numeric < 1; the fraction of overlap of the conditioningvariables, possibly of length 2 for x and y direction. Whenoverlap < 0, there will be _gaps_ between the data slices.xlim: the range for the x axis.ylim: the range for the y axis....: additional arguments to the panel function.x: a numeric vector.Details:In the case of a single conditioning variable ‘a’, when both‘rows’ and ‘columns’ are unspecified, a ‘close to square’ layoutis chosen with ‘columns >= rows’.In the case of multiple ‘rows’, the _order_ of the panel plots isfrom the bottom and from the left (corresponding to increasing‘a’, typically).A panel function should not attempt to start a new plot, but justplot within a given coordinate system: thus ‘plot’ and ‘boxplot’are not panel functions.The rendering of arguments ‘xlab’ and ‘ylab’ is not controlled by‘par’ arguments ‘cex.lab’ and ‘font.lab’ even though they areplotted by ‘mtext’ rather than ‘title’.Value:‘co.intervals(., number, .)’ returns a (‘number’ x 2) ‘matrix’,say ‘ci’, where ‘ci[k,]’ is the ‘range’ of ‘x’ values for the‘k’-th interval.References:Chambers, J. M. (1992) _Data for models._ Chapter 3 of_Statistical Models in S_ eds J. M. Chambers and T. J. Hastie,Wadsworth & Brooks/Cole.Cleveland, W. S. (1993) _Visualizing Data._ New Jersey: SummitPress.See Also:‘pairs’, ‘panel.smooth’, ‘points’.Examples:## Tonga Trench Earthquakescoplot(lat ~ long | depth, data = quakes)given.depth <- co.intervals(quakes$depth, number = 4, overlap = .1)coplot(lat ~ long | depth, data = quakes, given.v = given.depth, rows = 1)## Conditioning on 2 variables:ll.dm <- lat ~ long | depth * magcoplot(ll.dm, data = quakes)coplot(ll.dm, data = quakes, number = c(4, 7), show.given = c(TRUE, FALSE))coplot(ll.dm, data = quakes, number = c(3, 7),overlap = c(-.5, .1)) # negative overlap DROPS values## given two factorsIndex <- seq(length = nrow(warpbreaks)) # to get nicer default labelscoplot(breaks ~ Index | wool * tension, data = warpbreaks,show.given = 0:1)coplot(breaks ~ Index | wool * tension, data = warpbreaks,col = "red", bg = "pink", pch = 21,bar.bg = c(fac = "light blue"))## Example with empty panels:with(data.frame(state.x77), {coplot(Life.Exp ~ Income | Illiteracy * state.region, number = 3,panel = function(x, y, ...) panel.smooth(x, y, span = .8, ...))## y ~ factor -- not really sensible, but 'show off':coplot(Life.Exp ~ state.region | Income * state.division,panel = panel.smooth)})
使用coplot()绘制多元图相关推荐
- ggrcs包2.6版本已经上线,增加了绘制多元线性回归RCS(限制立方样条图)模块
目前本人写的ggrcs包新的2.6版本已经在CRAN上线,增加了多元线性回归分析模块,现在支持逻辑回归(logistic回归).cox回归和多元线性回归 需要的可以使用代码安装 install.pac ...
- 语言的MASS包干什么的_R语言绘制平行坐标图(PCP)示例
R语言绘制平行坐标图(PCP)示例前文在讲述冲击图(alluvial diagram)时提到了,它在某种形式上是平行坐标图(parallel coordinate plot,PCP)的一种变体,那么本 ...
- MATLAB绘制雷达图并导出矢量图到Visio编辑(论文用图)
MATLAB绘制雷达图并导出矢量图到Visio编辑(论文用图) 前言: matlab绘制雷达图 雷达图(Radar Chart)又被叫做蜘蛛网图(Spider Chart),适用于显示三个或更多的 ...
- R语言在图上标出点坐标_R语言绘制平行坐标图(PCP)示例
R语言绘制平行坐标图(PCP)示例 前文在讲述 时提到了,它在某种形式上是平行坐标图( parallel coordinate plot,PCP)的一种变体,那么本篇顺便提一下什么是平行坐标图. 平行 ...
- Matplotlib绘制象限图——支持中文、箭头、自定义轴线交点
Matplotlib绘制象限图--支持中文.箭头.自定义轴线交点 1. 效果图 2. 原理 2.1 绘制象限图步骤 2.1 添加文字到图表 3. 源码 参考 这篇博客将介绍如何使用matplotlib ...
- nyquist图怎么画matlab,用MATLAB绘制Nyquist图
<用MATLAB绘制Nyquist图>由会员分享,可在线阅读,更多相关<用MATLAB绘制Nyquist图(9页珍藏版)>请在人人文库网上搜索. 1.用MATLAB绘制Nyqu ...
- Python生物信息学⑥绘制热图及火山图
Python生物信息学⑥绘制热图及火山图 Python生物信息学③提取差异基因 通过上Python生物信息学③提取差异基因得到了该数据集的差异分析的两个关键参数,1.差异倍数(foldchange)以 ...
- sangerbox平台使用(三)绘制火山图
目前绘制火山图有很多工具,我们最常用的就是R语言,本次想向大家介绍的是一个在线工具直接绘制火山图-sangerbox 官方链接为:http://sangerbox.com/AllTools?tool_ ...
- ComplexHeatmap绘制热图(一)
讲起热图,大家都会比较熟悉,绘制热图方式比较多,这里介绍的是ComplexHeatmap包绘制热图,首先配置数据,这里的自动生成一个10X10的矩阵 data=matrix(rnorm(100),nr ...
最新文章
- 初级篇第六期:学习UITableView
- Dynamips与VMware配合搭建网络实验环境
- javascript继承的实现
- 源码安装sippyqt4 for ubuntu,anconda3,python3
- nmap配合shell使用
- 使用wrapper将java程序注册程windows服务后不生效
- java动态代理二cglib
- 解决java poi导出excel2003不能超过65536行的问题
- [LeetCode][JavaScript]Power of Three
- GCC 放弃将代码贡献版权强制转让给 FSF!
- Python基础--01
- 2018中国开源云超级英雄评选,等你报名!
- vscode调试时如何在launch.json中添加环境变量
- win10系统托盘图标不见了_Win10如何显示系统托盘所有图标
- AllenNLP框架学习笔记(入门篇)
- 分享几款好用到爆的 Chrome 插件!!你们不用,我寝食难安……
- VB6.0的MsgBox语句
- STM32固件库点亮LED灯
- 微信小程序--火车票查询
- NFTScan x TiDB丨一栈式 HTAP 数据库为 Web3 数据服务提供毫秒级多维查询