This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to label gene ID on volcano plot?

Hello everyone, I am trying to plot the volcano plot along with geneID label on it. However, my code doesn't work so I don't know what did I do wrong here. Here are my code:

myTopHits.df.ordered <- myTopHits.df[order(myTopHits.df$adj.P.Val), ]
myTopHits.df.ordered$geneID <- rownames(myTopHits.df.ordered) %in% rownames(myTopHits.df.ordered[1:10,])
View(myTopHits.df.ordered)
#now plot
vplot <- ggplot(myTopHits.df.ordered) +
  aes(y=-log10(adj.P.Val), x=logFC, text = paste("Symbol:", geneID)) +
  geom_text_repel(aes(x = logFC, y = -log10(adj.P.Val), label = ifelse(geneID == TRUE, rownames(myTopHits.df.ordered),""))) +
  geom_point(size=2) +
  labs(title="Volcano plot",
       subtitle = "Mus musculus") +
  theme_bw()
ggplotly(vplot)

For the results, I got the volcano plot but no geneID label on it and got the error messages:

Warning message:
In geom2trace.default(dots[[1L]][[1L]], dots[[2L]][[1L]], dots[[3L]][[1L]]) :
  geom_GeomTextRepel() has yet to be implemented in plotly.
  If you'd like to see this geom implemented,
  Please open an issue with your example code at
  https://github.com/ropensci/plotly/issues

Please help me out! I really appreciate all your helps! Thank you!

geom_text_repel ggplot plot volcano

Try this:

vplot <- ggplot(myTopHits.df.ordered) + aes(y=-log10(adj.P.Val), x=logFC, text = paste("Symbol:", geneID)) + 
geom_text_repel() + geom_point(size=2) + labs(title="Volcano plot", subtitle = "Mus musculus") + theme_bw()

vplot

Hi, I tried it but I got the error messages:

Error in `check_required_aesthetics()`:
! geom_text_repel requires the following missing aesthetics: label
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/rlang_error>
Error in `check_required_aesthetics()`:
! geom_text_repel requires the following missing aesthetics: label
Backtrace:
 1. base `<fn>`(x)
 2. ggplot2:::print.ggplot(x)
 4. ggplot2:::ggplot_build.ggplot(x)
 5. ggplot2 by_layer(function(l, d) l$compute_geom_1(d))
 6. ggplot2 f(l = layers[[i]], d = data[[i]])
 7. l$compute_geom_1(d)
 8. ggplot2 f(..., self = self)
 9. ggplot2:::check_required_aesthetics(...)

Try label instead of text:

vplot <- ggplot(myTopHits.df.ordered) + aes(y=-log10(adj.P.Val), x=logFC, label = paste("Symbol:", geneID)) + 
geom_text_repel() + geom_point(size=2) + labs(title="Volcano plot", subtitle = "Mus musculus") + theme_bw()

vplot

Thank you so much for your help! But this time I got the message:

Warning message: ggrepel: 10001 unlabeled data points (too many overlaps). Consider increasing max.overlaps

so I tried the code:

vplot <- ggplot(myTopHits.df.ordered) + aes(y=-log10(adj.P.Val), x=logFC, label = paste("Symbol:", geneID)) + geom_label_repel() + geom_point(size=2) + labs(title="Volcano plot", subtitle = "Mus musculus") + theme_bw() vplot

but I still got the error message:

Error in UseMethod("depth") : no applicable method for 'depth' applied to an object of class "NULL"

So you got a warning not an error while running my code. max.overlap is an argument in geom_text_repel. try to increase its value and see what you can get. check also the other arguments like the padding argument, try also to increase it

0 answers

No answers yet.

Log in to answer this question.