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. javascript - 享元模式

    享元模式笔记  运用共享技术有效的支持大量的细粒度对象,避免对象间拥有相同内容造成多余的开销  享元模式主要还是对其数据.方法共享分离,它将数据和方法分成内部数据.内部方法和外部数据.外部方法.  内 ...

  2. JavaWeb开发环境准备之Linux篇

    01 Linux环境准备 (本文在win10上使用 VMware12 + Ubuntu14.04)   1.JDK安装及相关配置 参考:http://blog.csdn.net/sxdtzhaoxin ...

  3. 大数据系列(5)——Hadoop集群MYSQL的安装

    前言 有一段时间没写文章了,最近事情挺多的,现在咱们回归正题,经过前面四篇文章的介绍,已经通过VMware安装了Hadoop的集群环境,相关的两款软件VSFTP和SecureCRT也已经正常安装了. ...

  4. C++STL - 模板的其他特性

    之前已经总结过函数模板和类模板了,对于模板还有一些其他的特性,这篇主要介绍这些特性.主要都是一些特殊情况. 模板的其他特性 1.缺省参数 (1)类模板的模板参数可以带有缺省值,实例化该模板时,如果提供 ...

  5. windows下OpenSSL加密证书安装步骤与使用方法

    OpenSSL加密证书一般用于签名认证,含私钥和公钥.在Linux系统中,OpenSSL一般是已经安装好了,可以直接使用.而在Windows系统中,是需要安装使用的. 最近在使用支付平台时,用到了Op ...

  6. Git版本控制常用命令整理

    基础命令: git init  初始化一个空仓库 git add 添加已经修改的工作区文件 git add newmodifiedfile git commit -m "log conten ...

  7. [django]django xlrd处理xls中日期转换问题

    xlrd会把xls文件中比如20160--03-01类型的时间转换成整数,那么我们如何保证xlrd读取进来的时间为2016-03-01格式呢? 使用xlrd中的xldate_as_tuple函数 代码 ...

  8. spark on yarn 提交任务出错

    Application ID is application_1481285758114_422243, trackingURL: http://***:4040Exception in thread ...

  9. 2016.10.29 NOIP模拟赛 PM 考试整理

    300分的题,只得了第三题的100分. 题目+数据:链接:http://pan.baidu.com/s/1o7P4YXs 密码:4how T1:这道题目存在着诸多的问题: 1.开始的序列是无法消除的( ...

  10. Hibernate注解配置

    在之前的第一次对框架的实际应用中,我使用的是Hibernate的xml配置方法,xml配置方法非常繁琐, 还是推荐所有使用Hibernate的人使用注解方式进行配置,在这篇文章中,我将列举出我们常用的 ...