转载自:http://site.douban.com/182577/widget/notes/12866356/note/267793990/
作为一个开源软件,R常常通过在人们厌烦了使用某个特定函数的时候提供一些代替函数来表现其友好性。例如,如果你再也不想在画相关性分析图时输入p-l-o-t这几个字母了,欢迎你输入s-p-l-o-m,当然在此之前你需要下载好lattice包并将其载入库内。
As open source software, R behaves quite friendly that it commonly gives people alternatives when they are tired of using one specific function :) For example, if you are unwilling to type p-l-o-t any more when you need to draw pair plots, you are welcomed to enter s-p-l-o-m with the lattice package downloaded from the internet and loaded to the library ahead.
> # Plot pair plots of returns using the splom function from the lattice package
> library(lattice)
> splom(Capm/100,pch=19,col=rgb(0,0,100,50,maxColorValue=255))
老实说,我个人不认为使用splom()函数是比plot()函数更好的选择。p-l-o-t是R中一个日常使用率极高的函数,即使我在夜里做梦时也能大声并清晰地说出这个函数的名字,但我却十有八九没法儿拼出所谓的s-p-o-x-x还是s-p-l-x-x函数的名字,更不用说splom()毫无进步,除非让画出来的图变得更加难以辨认和乱七八糟也算作进步。但是不要灰心气馁哦,亲!更好的替代函数的确是存在的。例如,你只需使用另一个基本绘画函数paris()。这个函数的使用方法和plot()函数几乎一样。
To be honest, I personally do not consider using splom() function rather than plot() function as a better choice. The p-l-o-t is a daily-used function in R of which the name can be spoken aloud even I am dreaming at night while I am unable to spell the name of the so-called s-p-o-x-x or s-p-l-x-x function nine times out of ten, let alone the splom() function makes no improvement unless making a plot unreadable and messy counts. However, keep your chin up, my friend. Better rather than worse alternatives do exist. For example, you can simply use another basic plotting function, pairs(). This function can be applied almost in the same way as the plot() function.
pairs(Capm/100,labels=c("Food","Durables","Construction","Market","Risk-free"),
pch=19,col=rgb(0,0,100,50,maxColorValue=255))
注意到在这个例子中,我使用了一个新的变量labels。这个变量可在不改变原始数据列名的情况下对相关性图进行重新标注。
Note that in this example, I add a new argument labels which relabels the pairs in intuitive names while does not rewrite the column names of raw data.
此外,我们还可以投入pcaPP包中的plotcov()函数和ellipse包中的plotcorr()函数的怀抱。
Also, we can turn to the plotcov() function in the pcaPP package and the plotcorr() function in the ellipse package.
plotcov()函数高效简洁省事地同时给出了数据组内各组数据间的相关性数值和分布形状。
The function plotcov() provides both the values and the shape of correlations of the dataset at the same time which is informative, concise and space-saving.
> # Plot pair plots of returns using the plotcov function from the pacPP package
> library(pcaPP)
> plotcov(cor(Capm/100),method1="correlation")
偶尔人们会过度追求极简主义,所以我们得出了如下由plotcorr()函数画出的图。
Sometimes people try so hard to make things concise, so they get an output as the function plotcorr() does.
> # Plot pair plots of returns using the plotcorr function from the ellipse package
> library(ellipse)
> plotcorr(cor(Capm/100),num=T,diag=F,type="upper")
作为一个无印良品风格控,在我不需要考虑-0.02691534和0,-0.09965299、-0.07210179、-0.07680539和-1,0.66885253、0.72093253和7 即 7 %,0.77307668、0.78501333和8即0.8之间的“巨大”差异时,我会毫不犹豫地表达我对plotcorr风格的喜爱。多数情况下,我们只需要用相关性分析图帮助我们判断线性相关性的存在趋势,因此0.77307668和0.78501333并没有鸿沟般的差别。同时,plotcorr()函数使人们通过设置type参数为“upper”、“lower” 和 “full”可以得到上三角、下三角或者完整的相关性矩阵。
I am a Muji-style addict which means I will undoubtedly love the plotcorr-style if I do not have to care about the “big” difference between -0.02691534 and 0, -0.09965299, -0.07210179, -0.07680539 and -1, 0.66885253, 0.72093253 and 7 meaning 7 percent, 0.77307668, 0.78501333 and 8 meaning 0.8. In most time, we use pair plots simply to identify trends of linear relationships, thus 0.77307668 does not significantly differ from 0.78501333. Also, the plotcorr() allows people to have a upper-triangle, lower-triangle or full correlation matrix on their plots by equaling the type argument to “upper”, “lower” and “full”.