How can I use geom_label_repel with EnhancedVolcano?
1
0
Entering edit mode
Loren ▴ 10
@a7f154f5
Last seen 3.4 years ago
United States

Hi,

I generated this beautiful plot using EnhancedVolcano. However, I would like the labels to be on the sides of the graph with arrows pointing to the DEG. I know I can use ggrepel with EnhancedVolcano but I am having trouble figuring out the code to go about that. What I want is to plot all the points but only label a select few and have them away from the plot. Can anyone help me?

Thanks in advance.

vplot <- EnhancedVolcano(myTopHits.df,
                lab = myTopHits.df$geneID,
                selectLab = allgenes,
                labFace = 'bold',
                boxedLabels = TRUE,
                labSize = 4,
                typeConnectors = "closed",
                drawConnectors = TRUE,
                widthConnectors = 0.75,
                colConnectors = 'black',
                lengthConnectors = unit(0.01, "npc"),
                maxoverlapsConnectors = 6,
                title = 'title',
                x = 'logFC',
                y = 'adj.P.Val',
                xlim = c(-7,7),
                ylim = c(0, 7),
                axisLabSize = 12,
                FCcutoff = 2,
                pCutoff = 0.05,
                cutoffLineType = 'longdash',
                colAlpha = 1,
                cutoffLineWidth = 1,
                legendPosition = 'bottom',
                legendLabSize = 10,
                legendIconSize = 3.0,
                gridlines.major = FALSE,
                gridlines.minor = FALSE,
                border = 'full',
                borderWidth = 0.5,
                raster = FALSE)

include your problematic code here with any corresponding output

vplot + geom_label_repel(mapping = aes(myTopHits.df[c(8,516,1381,1811,210, 528), ]))

Output:

nolabel + geom_label_repel(mapping = aes(myTopHits.df[c(8,516,1381,1811,210, 528), ]))
Error: Aesthetics must be either length 1 or the same as the data (2115): x

please also include the results of running the following in an R session

sessionInfo( )

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 11.4

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] EnhancedVolcano_1.10.0 ggrepel_0.9.1          gt_0.3.0              
 [4] DT_0.18                forcats_0.5.1          stringr_1.4.0         
 [7] dplyr_1.0.7            purrr_0.3.4            readr_1.4.0           
[10] tidyr_1.1.3            tibble_3.1.2           ggplot2_3.3.5         
[13] tidyverse_1.3.1        edgeR_3.34.0           limma_3.48.1          

loaded via a namespace (and not attached):
 [1] fs_1.5.0            usethis_2.0.1       lubridate_1.7.10   
 [4] devtools_2.4.2      ash_1.0-15          RColorBrewer_1.1-2 
 [7] httr_1.4.2          rprojroot_2.0.2     tools_4.1.0        
[10] backports_1.2.1     utf8_1.2.1          R6_2.5.0           
[13] KernSmooth_2.23-20  vipor_0.4.5         DBI_1.1.1          
[16] colorspace_2.0-2    withr_2.4.2         tidyselect_1.1.1   
[19] prettyunits_1.1.1   ggrastr_0.2.3       processx_3.5.2     
[22] ggalt_0.4.0         compiler_4.1.0      extrafontdb_1.0    
[25] cli_3.0.0           rvest_1.0.0         xml2_1.3.2         
[28] desc_1.3.0          scales_1.1.1        proj4_1.0-10.1     
[31] callr_3.7.0         digest_0.6.27       pkgconfig_2.0.3    
[34] htmltools_0.5.1.1   extrafont_0.17      sessioninfo_1.1.1  
[37] dbplyr_2.1.1        fastmap_1.1.0       maps_3.3.0         
[40] htmlwidgets_1.5.3   rlang_0.4.11        readxl_1.3.1       
[43] rstudioapi_0.13     generics_0.1.0      jsonlite_1.7.2     
[46] magrittr_2.0.1      Rcpp_1.0.7          ggbeeswarm_0.6.0   
[49] munsell_0.5.0       fansi_0.5.0         lifecycle_1.0.0    
[52] stringi_1.6.2       MASS_7.3-54         pkgbuild_1.2.0     
[55] grid_4.1.0          crayon_1.4.1        lattice_0.20-44    
[58] haven_2.4.1         hms_1.1.0           locfit_1.5-9.4     
[61] ps_1.6.0            pillar_1.6.1        pkgload_1.2.1      
[64] reprex_2.0.0        glue_1.4.2          remotes_2.4.0      
[67] BiocManager_1.30.16 modelr_0.1.8        vctrs_0.3.8        
[70] testthat_3.0.4      Rttf2pt1_1.3.8      cellranger_1.1.0   
[73] gtable_0.3.0        assertthat_0.2.1    cachem_1.0.5       
[76] broom_0.7.8         beeswarm_0.4.0      memoise_2.0.0      
[79] ellipsis_0.3.2
ggrepel RNASeq R EnhancedVolcano • 5.0k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 12 hours ago
United States

EnhancedVolcano already uses geom_text_repel for you, and there is an argument called 'selectLab' that you can use to select only those that you want to have labels for. See the vignette, particularly section 4.8

ADD COMMENT
0
Entering edit mode

I used that but the labels are still on top of the plots and you can't really tell which point corresponds to the label.

ADD REPLY
0
Entering edit mode

We cannot see the plot to which you're referring. Can you upload a screenshot via https://imgbb.com/ and then share the URL here?

ADD REPLY
0
Entering edit mode

Hello! The URL: https://ibb.co/5WsyKYq

Thanks in advance.

ADD REPLY
1
Entering edit mode

Thanks! I think that I know what you want to do, but, unfortunately, that level of customisation is not possible with EnhancedVolcano alone. To improve the visualisation, though, I would install the current package version from Github (I updated it yesterday - https://github.com/kevinblighe/EnhancedVolcano) and modify the values for min.segment.length and directionConnectors

To align labels on the left or right even requires some special coding with ggrepel on its own - see the section 'Align labels on the left or right edge' here: https://ggrepel.slowkow.com/articles/examples.html

ADD REPLY
1
Entering edit mode

Thank you so much!

ADD REPLY

Login before adding your answer.

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