https://zhuanlan.zhihu.com/p/23400450

 

R 语言矩阵散点图

EasyCharts· 15 天前

散点图矩阵因包含多种多副图片,因此含有更多的信息,特别是不同变量之间相关关系。本文介绍了四种绘制散点图矩阵的函数。graphics(pairs),car( spm),GGally(ggscatmat), GGally(ggpairs)四种。

① graphics 包 pairs 函数

data(trees)
panel.cor <- function(x, y, digits = 2, prefix = "", cex.cor, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- abs(cor(x, y))
txt <- format(c(r, 0.123456789), digits = digits)[1]
txt <- paste0(prefix, txt)
if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.5, txt, cex = cex.cor * r)
}
panel.hist <- function(x, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(usr[1:2], 0, 1.5) )
h <- hist(x, plot = FALSE)
breaks <- h$breaks; nB <- length(breaks)
y <- h$counts; y <- y/max(y)
rect(breaks[-nB], 0, breaks[-1], y, col = "cyan", ...)
}
pairs(trees, 
labels = c('树周长','树高','树体积'),
lower.panel=panel.cor,
upper.panel=panel.smooth,
diag.panel=panel.hist,
main = 'The Scatterplot Matrix of The Trees Data',
pch = 21,
bg = "orange",
line.main=1.5,
oma=c(2,2,3,2)
)

② car 包 spm 函数

#diagonal=c("density", "boxplot", "histogram", "oned", "qqplot", "none")
library(car)
data("trees")
spm(trees,
diagonal='histogram',
main='The Scatterplot Matrix of The Trees Data')

③GGally 包 ggscatmat 函数

library(GGally)
#ggscatmat(trees)
data("iris")
ggscatmat(iris, columns = 1:4,color = 'Species' )

④ GGally 包 ggpairs函数

library(ggplot2)
library(GGally)
data(tips,package="reshape")
#pairs(tips[,1:3])
pm1 <- ggpairs(
tips[,c(1,3,4,2)],
mapping = ggplot2::aes(color = sex,shape=sex,alpha = 0.4),
upper = list(continuous = "cor", combo = "box", discrete = "facetbar"),
lower = list(continuous = "points", combo = "facethist", discrete = "facetbar"),
diag = list(continuous = "densityDiag", discrete = "barDiag")
)
pm1

data(iris)
pm2 <- ggpairs(
iris[,c(1,2,5,3,4)],
mapping = ggplot2::aes(color = Species,shape=Species,alpha = 0.4),
upper = list(continuous = "density", combo = "box"),
lower = list(continuous = "points", combo = "dot"),
title = "Iris",
axisLabels ="internal")
pm2

data(diamonds, package="ggplot2")
diamonds.samp <- diamonds[sample(1:dim(diamonds)[1], 200), ]
# Custom Example
pm3 <- ggpairs(
diamonds.samp[, 1:5],
mapping = ggplot2::aes(color = cut),
upper = list(continuous = wrap("density", alpha = 0.5), combo = "box"),
lower = list(continuous = wrap("smooth", alpha = 0.3), combo = wrap("dot", alpha = 0.4)),
title = "Diamonds"
)
pm3

EasyCharts团队出品

帅的人都关注了EasyCharts团队^..^~

QQ交流群:454614789

微信公众号:EasyCharts

更多信息敬请查看: http://easychart.github.io/post/Easycharts/

pair correlation ggpair ggmatrix的更多相关文章

  1. [文学阅读] METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments

    METEOR: An Automatic Metric for MT Evaluation with Improved Correlation with Human Judgments Satanje ...

  2. KCF:High-Speed Tracking with Kernelized Correlation Filters 的翻译与分析(一)。分享与转发请注明出处-作者:行于此路

    High-Speed Tracking with Kernelized Correlation Filters 的翻译与分析 基于核相关滤波器的高速目标跟踪方法,简称KCF 写在前面,之所以对这篇文章 ...

  3. 相关系数(CORRELATION COEFFICIENTS)会骗人?

    CORRELATION COEFFICIENTS We've discussed how to summarize a single variable. The next question is ho ...

  4. Correlation and Regression

    Correlation and Regression Sample Covariance The covariance between two random variables is a statis ...

  5. [Statistics] Comparison of Three Correlation Coefficient: Pearson, Kendall, Spearman

    There are three popular metrics to measure the correlation between two random variables: Pearson's c ...

  6. c++ pair 使用

    1. 包含头文件: #include <utility> 2. pair 的操作: pair<T1,T2> p; pair<T1,T2> p(v1,v2); pai ...

  7. 论Pair的重要性

    这些天我在用React和D3做图表,从已经实现的图表里复制了一些坐标轴的代码,发现坐标轴上的n个点里,只有第一个点下面能渲染出文字提示,其余点下面都无法渲染出文字. 和组里的FL一起百思不得其解好几天 ...

  8. 2016 ACM/ICPC Asia Regional Dalian Online 1010 Weak Pair dfs序+分块

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submissio ...

  9. pair的使用

    #include<iostream> #include<cmath> #include<cstdio> #include<algorithm> #inc ...

随机推荐

  1. Linux 磁盘自检介绍

    在Linux系统中,有时候重启会耗费非常长的时间,如果你进一步检查细节,就会发现绝大部分时间都耗费在磁盘自检(fsck)上了,有时候遇到时间比较紧急的情况,磁盘自检耗费的时间非常长,真的是让人心焦火急 ...

  2. PHP中require和include路径问题总结

    1 绝对路径.相对路径和未确定路径 相对路径 相对路径指以.开头的路径,例如 ./a/a.php (相对当前目录) ../common.inc.php (相对上级目录), 绝对路径 绝对路径是以 / ...

  3. 实战:考虑性能--Solr索引的schema设计

    从 high level 的角度来看,schema.xml 结果如下,这个例子虽然不是一个真实的XML,但是简洁明了的传达了shema的概念. <schema> <types> ...

  4. send+recv注意事项

    [TOC] send 函数原型 ssize_t send( SOCKET s, const char *buf, size_t len, int flags ) 注意事项 待发送数据长度data_le ...

  5. Java报表工具FineReport导出EXCEL的四种API

    在实际的应用中会经常需要将数据导出成excel,导出的方式除原样导出还有分页导出.分页分sheet导出和大数据量导出.对于excel 2003版,由于限制了每个sheet的最大行数和列数,大数据量导出 ...

  6. Java Generics and Collections-2.1

    2.1 子类化以及替换原理 为什么List<Integer> 不是List<Number> 的子类? 首先看下面的代码,这段代码是编译不过的 package java_gene ...

  7. H5框架之Bootstrap(二)

    H5框架之Bootstrap(二) 突然感觉不知道写啥子,脑子里面没水了,可能是因为今晚要出去浪,哈哈~~~提前提醒大家平安夜要回家哦,圣诞节生00000000000这么多蛋....继续 上一篇的已经 ...

  8. highcharts基本配置和使用highcharts做手机端图标

    使用highcharts三个理由:1>手机适配2>大数据的支持3>svg的优势缺点:不开源.学习资料少 官方有基本的常规用法,一般都是基于jquery写的例子,也可以自己封装函数,用 ...

  9. maven中央仓库访问速度太慢的解决办法

    方法一:修改settings.xml eclipse中集成的maven的settings.xml文件,找了半年也没找到,我们放弃eclipse中的maven,下一个最新的maven,并在eclipse ...

  10. Struts2 token禁止重复提交表单

    如果服务器响应慢的情况下,用户会重复提交多个表单,这时候有两种设计思想: 1.在客户端使用JS技术,禁止客户重复提交表单.但是这样会使一些不使用浏览器方式登陆的人比如使用底层通信来攻击你的服务器 2. ...