R语言 如何在火山图上显示上调和下调最多的基因(例如前10个)?

66bbxpm5  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(330)

我想在VP上显示重要基因的基因标签,我如何设置一个阈值来显示数据集中上调和下调的前x个基因。
非常感谢!
数据代码

Pro_FvsM <- data.frame(log2FC = FprovM_df$log.foldchange_F_pro.M,
                  logpv = -log10(FprovM_df$pvalue))

Pro_FvsM$diffexpressed <- "NON-Significant"

Pro_FvsM$diffexpressed[Pro_FvsM$log2FC > 0.8] <- "UP"

Pro_FvsM$diffexpressed[Pro_FvsM$log2FC < -0.8] <- "DOWN"

GeneList <- FprovM_df$Genes

Pro_FvsM_2 <- cbind(Pro_FvsM, GeneList)

Pro_FvsM_2$genelabels <- ""

地块代码

ggplot(Pro_FvsM_2) + geom_point(aes(log2FC, logpv, col = diffexpressed)) + geom_text_repel(aes(log2FC, logpv), label = ifelse(Pro_FvsM_2$GeneList == TRUE, as.character(Pro_FvsM_2$GeneList), ""), box.padding = unit(0.75, "lines"), hjust = 0.35) + theme(legend.title = element_blank(), text = element_text(size = 15)) + scale_color_manual(values = c("red", "blue", "green"))
lmvvr0a8

lmvvr0a81#

你可以把数据分成子集,然后绘图,你没有提供一个可复制的例子,所以我从这里下载了一些类似的基因数据,然后把它作为df读入。

download.file("https://raw.githubusercontent.com/biocorecrg/CRG_RIntroduction/master/de_df_for_volcano.rds", "de_df_for_volcano.rds", method="curl")

代码:

df$diffexpressed[df$log2FoldChange > 0.8] <- "UP"
df$diffexpressed[df$log2FoldChange < -0.8] <- "DOWN"

# create subset of data meeting whatever criteria to use to label

dfLabel <- df[df$diffexpressed %in% c("UP", "DOWN"),]

情节:

ggplot(df) + 
  geom_point(aes(log2FoldChange, pvalue, col = diffexpressed)) +
  ggrepel::geom_label_repel(aes(log2FoldChange, pvalue, label = gene_symbol), 
                            data = dfLabel)  # specify `dfLabel` data

相关问题