l******e 发帖数: 125 | 1 想比较两样品表达谱的相似性,如何作出x-y轴散点图,>log2的红色,<-log2的蓝色,
中间的灰色。对matlab不懂,stanford 的SAM怎么用不了?
多谢! | l******e 发帖数: 125 | 2 R是不是也可以做到?有高人贴个程序或者样本么,多谢 | l**********1 发帖数: 5204 | 3 pls refer
> posted on FRIDAY, JULY 6, 2012
Fix Overplotting with Colored Contour Lines
I saw this plot in the supplement of a recent paper comparing microarray
results to RNA-seq results. Nothing earth-shattering in the paper - you've
probably seen a similar comparison many times before - but I liked how they
solved the overplotting problem using heat-colored contour lines to indicate
density. I asked how to reproduce this figure using R on Stack Exchange,
and my question was quickly answered by Christophe Lalanne.
Here's the R code to generate the data and all the figures here.
# Generate some data
library(MASS)
set.seed(101)
n <- 50000
X <- mvrnorm(n, mu=c(.5,2.5), Sigma=matrix(c(1,.6,.6,1), ncol=2))
# A color palette from blue to yellow to red
library(RColorBrewer)
k <- 11
my.cols <- rev(brewer.pal(k, "RdYlBu"))
## compute 2D kernel density, see MASS book, pp. 130-131
z <- kde2d(X[,1], X[,2], n=50)
# Make the base plot
plot(X, xlab="X label", ylab="Y label", pch=19, cex=.4)
# Draw the colored contour lines
contour(z, drawlabels=FALSE, nlevels=k, col=my.cols, add=TRUE, lwd=2)
# Add lines for the mean of X and Y
abline(h=mean(X[,2]), v=mean(X[,1]), col="gray", lwd=1.5)
# Add the correlation coefficient to the top left corner
legend("topleft", paste("R=", round(cor(X)[1,2],3)), bty="n")
## Other methods to fix overplotting
# Make points smaller - use a single pixel as the plotting charachter
plot(X, pch=".")
# Hexbinning
library(hexbin)
plot(hexbin(X[,1], X[,2]))
# Make points semi-transparent
library(ggplot2)
qplot(X[,1], X[,2], alpha=I(.1))
# The smoothScatter function (graphics package)
smoothScatter(X)
*****
cited
from
http://gettinggeneticsdone.blogspot.co.uk/2012/07/fix-overplott
ps: original hint was from one former mitbbs post
同主题阅读:R: how to convert a scatter plot to a contour color plot?
[版面:统计][首篇作者:StatsGuy] , 2011年03月31日15:17
http://www.mitbbs.com/article_t/Statistics/31271563.html
【在 l******e 的大作中提到】 : R是不是也可以做到?有高人贴个程序或者样本么,多谢
|
|