Ggplot 没有为火山图标记所有有趣的肽

发布于 2025-01-17 00:43:29 字数 2221 浏览 2 评论 0原文

我有一个包含 2479 个肽及其序列、p 值和对数倍变化的数据框。

# A tibble: 6 x 3
  Sequence             p log2fold
  <chr>            <dbl>    <dbl>
1 FLENEDR          0.343    1.21 
2 DTEEEDFHVDQATTVK 0.270    0.771
3 DTEEEDFHVDQATTVK 0.112    1.18 
4 SCRASQSVSSSF     0.798    0.139
5 RLSCTTSGF        0.739    0.110
6 SCRASQSVSSSY     0.209    0.375

我正在尝试制作火山图,同时标记上调和下调的肽。然而,由于某种原因,ggplot 只使用 6 个标签。我不知道为什么。

我尝试了很多不同的事情。我尝试在表达列中使用上调和下调,我尝试增加和减少我的截止值来检查这是否是一个问题。我使用 ggrepel 尝试将它们更加居中。似乎什么都不起作用。我对代码的最新尝试就在这段代码中。

基本上作为最后的手段,我创建了一个新组,只带走显着变化和折叠变化的肽,最终得到 39 个肽。然后我用它作为标题并匹配两个数据帧之间的肽。

出现的另一个问题是在我的图例中,自从使用 geom_text_repel 后出现了一个字符。我不知道这是如何或为何发生的。

library(ggplot2)
library(ggrepel)
library(tidyverse)

Volc <- R_volcano

expression <- ifelse(Volc$p < 0.05 & abs (Volc$log2fold) >=1, ifelse(Volc$log2fold>1, 'up', 'down'), 'stable')
Volc <- cbind(Volc, expression)

colnames(Volc)[1] <- 'Sequencenames'
Volc["group"] <- "NotSignificant"
Volc[which(Volc['p'] < 0.05 & abs(Volc['log2fold']) < 1 ),"group"] <- "Significant"
Volc[which(Volc['p'] > 0.05 & abs(Volc['log2fold']) > 1 ),"group"] <- "FoldChange"
Volc[which(Volc['p'] < 0.05 & abs(Volc['log2fold']) > 1 ),"group"] <- "Significant&FoldChange"
VolcFilter <- Volc %>% filter(group=="Significant&FoldChange")

p <- ggplot(data = Volc, aes(x = log2fold, y = -log10(p), colour=expression, label='Sequencenames')) +
  geom_point(alpha=0.4, size=2) +
  scale_color_manual(values=c("blue", "grey","red"))+
  xlim(c(-4.5, 4.5)) +
  geom_vline(xintercept=c(-1,1),lty=4,col="black",lwd=0.8) +
  geom_hline(yintercept = 1.301,lty=4,col="black",lwd=0.8) +
  geom_text_repel(data=head(VolcFilter), aes(label=Sequencenames))+
  labs(x="log2(fold change)",
       y="-log10 (p-value)",
       title="Differential expression")  +
  theme_bw()+
  theme(plot.title = element_text(hjust = 0.5), 
        legend.position="right", 
        legend.title = element_blank())
  
p

在此处输入图像描述 在此处输入图像描述

非常感谢任何帮助。对 R 来说相当陌生。

I have a dataframe containing 2479 peptides with their sequence, p-value and logfold change.

# A tibble: 6 x 3
  Sequence             p log2fold
  <chr>            <dbl>    <dbl>
1 FLENEDR          0.343    1.21 
2 DTEEEDFHVDQATTVK 0.270    0.771
3 DTEEEDFHVDQATTVK 0.112    1.18 
4 SCRASQSVSSSF     0.798    0.139
5 RLSCTTSGF        0.739    0.110
6 SCRASQSVSSSY     0.209    0.375

I'm trying to make a volcano plot while labelling the up and downregulated peptides. However, for some reason, ggplot only uses 6 labels. I have no idea why.

I have trying loads of different things. I tried using up and downregulation in expression column, I tried increasing and decreasing my cut-off values to check if this was a problem. I used ggrepel to try and center them out more. Nothing seems to be working. My latest tries with the code is in this code.

Basically as a last resort I made a new group and only took the significant and fold change peptides with me, resulting in 39 peptides. Then I used this as header and matched peptides between the two dataframes.

Another problem that arises is in my legend, a character appears since using geom_text_repel. I have no idea how or why this is happening.

library(ggplot2)
library(ggrepel)
library(tidyverse)

Volc <- R_volcano

expression <- ifelse(Volc$p < 0.05 & abs (Volc$log2fold) >=1, ifelse(Volc$log2fold>1, 'up', 'down'), 'stable')
Volc <- cbind(Volc, expression)

colnames(Volc)[1] <- 'Sequencenames'
Volc["group"] <- "NotSignificant"
Volc[which(Volc['p'] < 0.05 & abs(Volc['log2fold']) < 1 ),"group"] <- "Significant"
Volc[which(Volc['p'] > 0.05 & abs(Volc['log2fold']) > 1 ),"group"] <- "FoldChange"
Volc[which(Volc['p'] < 0.05 & abs(Volc['log2fold']) > 1 ),"group"] <- "Significant&FoldChange"
VolcFilter <- Volc %>% filter(group=="Significant&FoldChange")

p <- ggplot(data = Volc, aes(x = log2fold, y = -log10(p), colour=expression, label='Sequencenames')) +
  geom_point(alpha=0.4, size=2) +
  scale_color_manual(values=c("blue", "grey","red"))+
  xlim(c(-4.5, 4.5)) +
  geom_vline(xintercept=c(-1,1),lty=4,col="black",lwd=0.8) +
  geom_hline(yintercept = 1.301,lty=4,col="black",lwd=0.8) +
  geom_text_repel(data=head(VolcFilter), aes(label=Sequencenames))+
  labs(x="log2(fold change)",
       y="-log10 (p-value)",
       title="Differential expression")  +
  theme_bw()+
  theme(plot.title = element_text(hjust = 0.5), 
        legend.position="right", 
        legend.title = element_blank())
  
p

enter image description here
enter image description here

Any help is much appreciated. Fairly new to R.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文