https://zhuanlan.zhihu.com/p/23400450git
① graphics 包 pairs 函數github
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 函數app
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團隊出品post
帥的人都關注了EasyCharts團隊^..^~this
QQ交流羣:454614789spa
微信公衆號:EasyCharts3d
更多信息敬請查看: http://easychart.github.io/post/Easycharts/orm