hhh*_*hhh 2 plot r ggplot2 weka tidyverse
我想创建一个大小的网格划分N倍N哪里N是字段数。我试图得到的网格图有点像 Weka 中的图:一个多图,其中每一行都是数据框的一个字段,每列也是一个字段。诀窍是我想获得矩阵散点图的更通用版本。我想要更丰富的数据,没有重复:例如,对角线值可以有分布。
威卡。矩阵散点图浪费了很多空间,我们可以丰富它吗?
基本的R解决方案1.plot(iris)同样的浪费空间的问题,为什么我们有对角线?
看起来像是从维基百科以某种方式使用 R 基本命令创建的 R 解决方案 2。
R 中的小演示(计算时间太长)
library(gridExtra)
library(grid)
library(ggplot2)
#library(lattice)
data(iris)
p1 <- ggplot(data=iris,aes(x=Sepal.Length, y=Sepal.Length)) + geom_point()
p2 <- ggplot(data=iris,aes(x=Sepal.Length, y=Sepal.Width)) + geom_point()
p3 <- ggplot(data=iris,aes(x=Sepal.Length, y=Petal.Length)) + geom_point()
p4 <- ggplot(data=iris,aes(x=Sepal.Length, y=Petal.Width)) + geom_point()
p5 <- ggplot(data=iris,aes(x=Sepal.Length, y=Species)) + geom_point()
grid.arrange(p1, p2, p3, p4, p5, ncol=length(names(iris)))
#ERROR: In as.list(X): reached elapsed time limit
# https://cran.r-project.org/web/packages/gridExtra/vignettes/arrangeGrob.html
Run Code Online (Sandbox Code Playgroud)
及其会话信息
version 3.4.1 (2017-06-30)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.1
Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale:
[1] C
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] lattice_0.20-35 gridExtra_2.3 BAS_1.4.7 statsr_0.0.1 dplyr_0.7.4
[6] ggplot2_2.2.1
loaded via a namespace (and not attached):
[1] Rcpp_0.12.14 knitr_1.17 bindr_0.1 magrittr_1.5
[5] munsell_0.4.3 colorspace_1.3-2 xtable_1.8-2 R6_2.2.2
[9] rlang_0.1.4 plyr_1.8.4 tools_3.4.1 gtable_0.2.0
[13] htmltools_0.3.6 lazyeval_0.2.0 assertthat_0.2.0 digest_0.6.13
[17] tibble_1.3.4 bindrcpp_0.2 shiny_1.0.5 glue_1.2.0
[21] mime_0.5 labeling_0.3 compiler_3.4.1 scales_0.4.1
[25] httpuv_1.3.5 pkgconfig_2.0.1
>
Run Code Online (Sandbox Code Playgroud)
这是非常耗时的:对于我的 1.3GHz MBA,它甚至没有完成并且需要很长时间来绘制或根本不绘制。我想找到更现代的方法来制作广义散点图。
有趣的附带问题
关键搜索词是
广义对图,广义散点图矩阵
散点图矩阵
哈德利在这里讨论了 2012 年。我们在下面列出了尝试实现与原始矩阵散点图相同的探索性分析的替代方案。
在撰写本文时,GGally 看起来是与 ggplot 和tideverse 合作的最佳人选。它是用 ggplot2 构建的,您可以在此处进一步了解它。
备择方案
Marco Sandri 建议的 GGally
dev.off()
library(GGally)
ggpairs(iris)
Run Code Online (Sandbox Code Playgroud)
对较大的数据集,您可能需要改变cardinality_threshold,使得
ggpairs(movies[1:15,1:10], cardinality_threshold = 211)
Run Code Online (Sandbox Code Playgroud)
电影数据来自这里的最后一个任务
对于较大的数据集,这看起来有些难以阅读。
唉! 您可以使用颜色并自定义 ggpairs 图
| 归档时间: |
|
| 查看次数: |
10756 次 |
| 最近记录: |