Setting colour palettes correctly for correlation plots
1
0
Entering edit mode
5.4 years ago
exin ▴ 60

Newbie R question:

I currently use the standard blue-red palette for plotting a correlation plot:

> col<- colorRampPalette(c("blue", "white", "red"))(20)

but my data only covers a R value or ~0.2 to 1, hence white is set at ~0.4, which is misleading.

How do I select only "some blue and all red" of the spectrum, still with 20 divisions?

Undesired scale colours & associated plot: https://ibb.co/Hx6bzdM

correlation plot R • 2.8k views
ADD COMMENT
0
Entering edit mode

can you provide the entire code you use for the heatmap generation, not just the color part? (different heatmap functions may have different capabilities of tuning the colors)

ADD REPLY
0
Entering edit mode

Here we go:

cts<- read.table("cor_gene.txt",header=T,row.names=1,sep="\t")
cts<- cts[rowSums(cts)>0,]
cts$var<- apply(cts, 1, var)
ctsv<- cts[cts$var >= quantile(cts$var, c(.95)), ]
ctsv$var <- NULL
resv<-cor(ctsv,method="pearson")

library("RColorBrewer")
library("pheatmap")

col<- colorRampPalette(c("blue", "white", "red"))(20)
pheatmap(resv, col=col, cluster_cols=T, cluster_rows=T, 
         show_rownames=T, scale = "none", border_color=F,
         fontsize_row=5.2, fontsize_col=5.2, fontsize=8, 
         cellheight=5, cellwidth=5, clustering_method = "complete")
ADD REPLY
1
Entering edit mode
5.4 years ago

Check the breaks option. Have a look at this pheatmap tutorial.

ADD COMMENT
0
Entering edit mode

Looks like what I need... Thank you! I'll look into that.

ADD REPLY

Login before adding your answer.

Traffic: 1318 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6