specificy ggrepel which genes not overlap in a scatterplot
1
0
Entering edit mode
2.6 years ago
camillab. ▴ 160

Hi!

I want to make a scatterplot where the down-regulated genes (log2FC <= -1.5 & p_value <= 0.05) are highlighted in blue and the up-regulated (log2FC >= 1.5 & p_value <= 0.05) in red but, even if I used ggrepel I still have a couple of genes that despite all, still overlap because they re very close to each other. is there a way to specify which gene I do not want to overlap? here is my code:

#subset
dfup <- Dpg_JNKst %>%  filter(log2FC >= 1.5 & p_value <= 0.05)
dfdown <- Dpg_JNKst %>%  filter(log2FC <= -1.5 & p_value <= 0.05)

#scatterplot 
library(ggplot2)
library(ggrepel)
ggplot(data = Dpg_JNKst, aes(x= log2FC, y= -1*log10(p_value)))+  ggtitle("Stress-activated kinase signaling cascade") + 
  geom_point() + 
  geom_point(data= dfdown, aes(x= log2FC, y= -1*log10(p_value)), color = "blue")+
  geom_point(data= dfup, aes(x= log2FC, y= -1*log10(p_value)), color = "red")+
  geom_vline(xintercept = 1.5,linetype = "dashed")+ 
  geom_vline(xintercept = -1.5,linetype = "dashed")+
  geom_hline(yintercept = -1*log10(0.05),linetype = "dashed") +
  geom_hline(yintercept = -1*log10(0.01),linetype = "dashed", color = "black")+ 
  geom_text(mapping=aes(x=-7,y=2.0),label=paste("0.01"), color = "black", size = 2.5, vjust=-0.5) +
  geom_hline(yintercept = -1*log10(0.001),linetype = "dashed", color = "black") +
  geom_text(mapping=aes(x=-7,y=3.0),label=paste("0.001"), color = "black", size = 2.5, vjust=-0.5)+
  geom_text(mapping=aes(x=-7,y=1.30),label=paste("0.05"), size = 2.5, vjust=-0.5) +
  geom_text_repel(data=dfdown, aes(label=`Associated.Gene.Name`), color = "blue") +
  geom_text_repel(data=dfup, aes(label=`Associated.Gene.Name`), color = "red", max.overlaps = Inf, nudge_x = .15, box.padding = 1)

Maybe is a stupid question but thank you in advance!

camilla

R ggplot2 ggrepel • 1.7k views
ADD COMMENT
1
Entering edit mode

probably you can try a data frame containing only genes of interest and pass it to geom_text_repel, instead of using up and down regulated genes.

ADD REPLY
3
Entering edit mode
2.6 years ago

I am not sure, if I fully understand what outcome you are trying to achieve, but I think you have a few options that you could try:

  • use e.g. geom_text_repel(..., force=3), which should spread out the labels more (default value is 1).
  • try geom_text_repel(..., force_pull=0.5), which allows labels to be placed further away from their corresponding data points (default value is 1).
  • don't allow geom_text_repel(..., max.overlaps=Inf), because this renders labels even if they overlap too many things. By default, a label that overlaps 10 items will not be displayed.
  • reorder the factor levels of dfup[,"Associated.Gene.Name"] and dfdown[,"Associated.Gene.Name"] such that the gene name you want to be shown for sure are last (?).
  • Set the Associated.Gene.Name of genes you do not want to be labelled to NA in dfup & dfdown and use geom_text_repel(..., na.rm=TRUE)

I hope, something in this list works. Otherwise, consider showing a screenshot of the issue that you are trying to resolve.

ADD COMMENT

Login before adding your answer.

Traffic: 1787 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