简体   繁体   English

基于倍数富集的R中的着色散点图

[英]Coloring scatterplot in R based on fold enrichment

I'm very new to R and have tried to search around for an answer to my question, but couldn't find quite what I was looking for (or I just couldn't figure out the right keywords to include!). 我是R的新手,曾尝试寻找问题的答案,但是找不到我想要的东西(或者我只是找不到适合的关键词!)。 I think this is a fairly common task in R though, I am just very new. 我认为这是R中相当普遍的任务,但我只是一个新手。

I have ax vs y scatterplot and I want to color those points for which there is at least a 2-fold enrichment, ie where x/y>=2 . 我有ax vs y散点图,我想为那些至少有2倍富集的点着色,即x / y> = 2。 Since my values are expressed as log2 values, the the transformed value needs to be x/y>=4. 由于我的值表示为log2值,因此变换后的值必须为x / y> = 4。

I currently have the scatterplot plotted with 我目前有散点图

plot(log2(counts[,40], log2(counts[,41))

where counts is a .csv imported files and 40 & 41 are my columns of interested. 其中counts是一个.csv导入文件,而40和41是我感兴趣的列。

I've also created a column for fold change using 我还创建了一个列,用于使用

counts$fold<-counts[,41]/counts[,40]

I don't know how to incorporate these two pieces of information... Ultimately I want a graph that looks something like the example here: http://s17.postimg.org/s3k1w8r7j/error_messsage_1.png where those points that are at least two-fold enriched will colored in blue. 我不知道如何合并这两个信息...最终,我想要一个看起来像此处示例的图形: http : //s17.postimg.org/s3k1w8r7j/error_messsage_1.png这些点位于至少两倍浓缩后会变成蓝色。

Any help would be greatly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

Is this what you're looking for: 这是您要找的东西吗?

# Fake data
dat = data.frame(x=runif(100,0,50), y = rnorm(100, 10, 2))

plot(dat$x, dat$y, col=ifelse(dat$x/dat$y > 4, "blue", "red"), pch=16)

The ifelse statement creates a vector of "blue" and "red" (or whatever colors you want) based on the values of dat$x/dat$y and plot uses that to color the points. ifelse语句创建的“蓝色”和“红色”(或任何颜色你想要的)基础上的值的矢量dat$x/dat$yplot使用了着色点。

This might be helpful if you've never worked with colors in R . 如果您从未使用过R颜色, 这可能会有所帮助

在此处输入图片说明

Another option is to use ggplot2 instead of base graphics. 另一种选择是使用ggplot2代替基本图形。 Here's an example: 这是一个例子:

library(ggplot2)
ggplot(dat, aes(x,y, colour=cut(x/y, breaks=c(-1000,4,1000), 
                                labels=c("<=4",">4")))) + 
  geom_point(size=5) + 
  labs(colour="x/y")

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM