R 下三角相关热图

R 下三角相关热图,r,ggplot2,heatmap,R,Ggplot2,Heatmap,我试图在R中产生一个低三角形的成对关联热图 以下是数据: set.seed(1) mat <- matrix(rnorm(6*10),ncol=6,nrow=10) colnames(mat) <- c("s.-.+.1","s.-.+.2","s.-.+.3","s.+.-.1","s.+.-.2","s.+.-.3") 这给了我: 因此,彩色元素分散在整个区域,而不是局限于较低的三角形 知道问题出在哪里吗?嗯,我复制了你的剧本,这是我的情节 换衣服 ggplot(cor.mat

我试图在R中产生一个低三角形的成对关联热图

以下是数据:

set.seed(1)
mat <- matrix(rnorm(6*10),ncol=6,nrow=10)
colnames(mat) <- c("s.-.+.1","s.-.+.2","s.-.+.3","s.+.-.1","s.+.-.2","s.+.-.3")
这给了我:

因此,彩色元素分散在整个区域,而不是局限于较低的三角形


知道问题出在哪里吗?

嗯,我复制了你的剧本,这是我的情节

换衣服

ggplot(cor.mat.df ,aes(sample2, sample1, fill=correlation))+
  geom_tile(color="white")+
  scale_fill_gradient2(low="blue", high="red", mid="white", midpoint=0, limit=c(-1,1), space="Lab", name="Pearson\nCorrelation")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,vjust=1,size=10,hjust=1))+
  coord_fixed()+
  labs(x="",y="")

我的会话信息:

R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Spanish_Colombia.1252  LC_CTYPE=Spanish_Colombia.1252   
[3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C                     
[5] LC_TIME=Spanish_Colombia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8      digest_0.6.11    assertthat_0.1   grid_3.3.2       plyr_1.8.4      
 [6] gtable_0.2.0     magrittr_1.5     scales_0.4.1     stringi_1.1.2    reshape2_1.4.2  
[11] lazyeval_0.2.0   labeling_0.3     tools_3.3.2      stringr_1.1.0    munsell_0.4.3   
[16] colorspace_1.3-2 tibble_1.2

它似乎起作用了。我认为您在ggplot函数中使用了错误的变量:cor.mat.df应该是cor.df。
ggplot(cor.mat.df ,aes(sample2, sample1, fill=correlation))+
  geom_tile(color="white")+
  scale_fill_gradient2(low="blue", high="red", mid="white", midpoint=0, limit=c(-1,1), space="Lab", name="Pearson\nCorrelation")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45,vjust=1,size=10,hjust=1))+
  coord_fixed()+
  labs(x="",y="")
ggplot(cor.df, aes(sample2, sample1, fill=correlation))+
  geom_tile(color="white")+
  scale_fill_gradient2(low="blue", high="red", mid="white", midpoint=0, limit=c(-1,1), space="Lab", name="Pearson\nCorrelation")+
  theme_bw()+
  theme(axis.text.x=element_text(angle=45, vjust=1, size=10, hjust=1))+
  coord_fixed()+
  labs(x="",y="")
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Spanish_Colombia.1252  LC_CTYPE=Spanish_Colombia.1252   
[3] LC_MONETARY=Spanish_Colombia.1252 LC_NUMERIC=C                     
[5] LC_TIME=Spanish_Colombia.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggplot2_2.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.8      digest_0.6.11    assertthat_0.1   grid_3.3.2       plyr_1.8.4      
 [6] gtable_0.2.0     magrittr_1.5     scales_0.4.1     stringi_1.1.2    reshape2_1.4.2  
[11] lazyeval_0.2.0   labeling_0.3     tools_3.3.2      stringr_1.1.0    munsell_0.4.3   
[16] colorspace_1.3-2 tibble_1.2