散点图矩阵

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_41100555/article/details/79943437
> install.packages('GGally')
> library(GGally)
> theme_set(theme_minimal(20))   #设置主题
> set.seed(1836)
> pf_subset <- pf[,c(2,15)]
> names(pf_subset)
[1] "age"                "www_likes_received"
> pf_subset <- pf[,c(2:15)]
> names(pf_subset)
 [1] "age"                   "dob_day"               "dob_year"              "dob_month"            
 [5] "gender"                "tenure"                "friend_count"          "friendships_initiated"
 [9] "likes"                 "likes_received"        "mobile_likes"          "mobile_likes_received"
[13] "www_likes"             "www_likes_received"   
> ggpairs(pf_subset[sample.int(nrow(pf_subset),1000),])
 plot: [5,1] [===========================-----------------------------------------------------------------] 29% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [5,2] [===========================-----------------------------------------------------------------] 30% est:13s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [5,3] [============================----------------------------------------------------------------] 30% est:13s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [5,4] [============================----------------------------------------------------------------] 31% est:13s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [6,5] [===================================---------------------------------------------------------] 38% est:12s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [7,5] [==========================================--------------------------------------------------] 45% est:10s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [8,5] [================================================--------------------------------------------] 53% est: 9s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [9,5] [=======================================================-------------------------------------] 60% est: 7s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [10,5] [=============================================================------------------------------] 67% est: 6s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [11,5] [===================================================================------------------------] 74% est: 5s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [12,5] [==========================================================================-----------------] 81% est: 3s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [13,5] [================================================================================-----------] 88% est: 2s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
 plot: [14,5] [=======================================================================================----] 95% est: 1s `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Warning messages:                                                                                                       
1: Removed 2 rows containing non-finite values (stat_boxplot). 
2: Removed 2 rows containing non-finite values (stat_boxplot). 
3: Removed 2 rows containing non-finite values (stat_boxplot). 
4: Removed 2 rows containing non-finite values (stat_boxplot). 
5: Removed 2 rows containing non-finite values (stat_boxplot). 
6: Removed 2 rows containing non-finite values (stat_boxplot). 
7: Removed 2 rows containing non-finite values (stat_boxplot). 
8: Removed 2 rows containing non-finite values (stat_boxplot). 
9: Removed 2 rows containing non-finite values (stat_boxplot).

这里写图片描述
你可能还会发现:变量标签是在散点图矩阵的外边缘上,而非对角线上。如果你希望标签在对角线上,你可以在 ggpairs 命令中设置 axisLabels = ‘internal’ 参数。
当出现大量变量的时候,用图形矩阵会很方便。

创造热图

nci <- read.table("nci.tsv.crdownload")
colnames(nci) <- c(1:64)

R 中的融合数据框

nci <- read.table("nci.tsv.crdownload")
colnames(nci) <- c(1:64)
library(reshape2)
nci.long.samp <- melt(as.matrix(nci[1:200,]))
names(nci.long.samp) <- c('gene','case','value')
head(nci.long.samp)

ggplot(aes(y=gene,x=case,fill=value),data=nci.long.samp)+
  geom_tile()+
  scale_fill_gradientn(colours=colorRampPalette(c('blue','red'))(100))

这里写图片描述

展开阅读全文

没有更多推荐了,返回首页