ggtranscript icon indicating copy to clipboard operation
ggtranscript copied to clipboard

lines extend to gene model with geom_junction_label_repel

Open srisarya opened this issue 1 year ago • 3 comments

Hi, Firstly, thanks for this R package; it's already really useful to me, and it's quite user friendly :) However, I'm having an issue with the geom_junction_label_repel 'geom' and getting different results from the examples in the README. I was expecting the lines coming from the labels to connect to the junction lines, but instead, they connect to the gene models. I have tried this both with the SOD gene example in the GitHub instructions and with my own data. I have copied the resulting plot from copying the given code into R below.

sod1_201_exons %>%
  ggplot(aes(
    xstart = start,
    xend = end,
    y = transcript_name
  )) +
  geom_range(
    fill = "white", 
    height = 0.25
  ) +
  geom_range(
    data = sod1_201_cds
  ) + 
  geom_intron(
    data = to_intron(sod1_201_exons, "transcript_name")
  ) + 
  geom_junction(
    data = sod1_junctions,
    junction.y.max = 0.5
  ) +
  geom_junction_label_repel(
    data = sod1_junctions,
    aes(label = round(mean_count, 2)),
    junction.y.max = 0.5
  )

image

My session info is below:

> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

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

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

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

other attached packages:
 [1] forcats_0.5.2        stringr_1.4.1        purrr_0.3.5          readr_2.1.3          tidyr_1.2.1          tibble_3.1.8         tidyverse_1.3.2      patchwork_1.1.2.9000
 [9] ggsci_2.9            ggplot2_3.4.0        rtracklayer_1.54.0   GenomicRanges_1.46.1 GenomeInfoDb_1.30.1  IRanges_2.28.0       S4Vectors_0.32.4     BiocGenerics_0.40.0 
[17] dplyr_1.0.10         ggtranscript_0.99.9 

loaded via a namespace (and not attached):
 [1] bitops_1.0-7                matrixStats_0.62.0          fs_1.5.2                    lubridate_1.9.0             bit64_4.0.5                 httr_1.4.4                 
 [7] tools_4.1.2                 backports_1.4.1             utf8_1.2.2                  R6_2.5.1                    DBI_1.1.3                   colorspace_2.0-3           
[13] withr_2.5.0                 tidyselect_1.2.0            bit_4.0.4                   compiler_4.1.2              textshaping_0.3.6           cli_3.4.1                  
[19] rvest_1.0.3                 Biobase_2.54.0              xml2_1.3.3                  DelayedArray_0.20.0         labeling_0.4.2              scales_1.2.1               
[25] systemfonts_1.0.4           Rsamtools_2.10.0            XVector_0.34.0              pkgconfig_2.0.3             MatrixGenerics_1.6.0        dbplyr_2.2.1               
[31] rlang_1.0.6                 readxl_1.4.1                rstudioapi_0.14             BiocIO_1.4.0                generics_0.1.3              farver_2.1.1               
[37] jsonlite_1.8.3              BiocParallel_1.28.3         vroom_1.6.0                 googlesheets4_1.0.1         RCurl_1.98-1.9              magrittr_2.0.3             
[43] GenomeInfoDbData_1.2.7      Matrix_1.5-1                Rcpp_1.0.9                  munsell_0.5.0               fansi_1.0.3                 lifecycle_1.0.3            
[49] stringi_1.7.8               yaml_2.3.6                  SummarizedExperiment_1.24.0 zlibbioc_1.40.0             grid_4.1.2                  parallel_4.1.2             
[55] ggrepel_0.9.2               crayon_1.5.2                lattice_0.20-45             Biostrings_2.62.0           haven_2.5.1                 hms_1.1.2                  
[61] knitr_1.40                  pillar_1.8.1                rjson_0.2.21                reprex_2.0.2                XML_3.99-0.12               glue_1.6.2                 
[67] modelr_0.1.9                vctrs_0.5.0                 tzdb_0.3.0                  cellranger_1.1.0            gtable_0.3.1                assertthat_0.2.1           
[73] xfun_0.34                   broom_1.0.1                 restfulr_0.0.15             ragg_1.2.4                  googledrive_2.0.0           gargle_1.2.1               
[79] GenomicAlignments_1.30.0    timechange_0.1.1            ellipsis_0.3.2

Could you please advise what to do? Thanks!

srisarya avatar Nov 15 '22 17:11 srisarya

Hi - thanks for your feedback on ggtranscript!

I'm unable to reproduce this issue and can't spot anything wrong in the code or environment. The grey boxes representing the CDS (which should be generated by geom_range(data = sod1_201_cds)) are also missing from your plot - are you sure this is the plot generated by your attached code?

On a fresh R session, could you try running the code below and let me know if the outputted plot still has the geom_junction_label_repel issue:

library(ggtranscript)
library(ggplot2)
library(dplyr)
library(magrittr)

sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon")
sod1_cds <- sod1_annotation %>% dplyr::filter(type == "CDS")

sod1_201_exons <- sod1_exons %>% dplyr::filter(transcript_name == "SOD1-201")
sod1_201_cds <- sod1_cds %>% dplyr::filter(transcript_name == "SOD1-201")
sod1_202_exons <- sod1_exons %>% dplyr::filter(transcript_name == "SOD1-202")
sod1_202_cds <- sod1_cds %>% dplyr::filter(transcript_name == "SOD1-202")

sod1_junctions <- sod1_junctions %>%
  dplyr::mutate(transcript_name = "SOD1-201")

sod1_201_exons %>%
  ggplot(aes(
    xstart = start,
    xend = end,
    y = transcript_name
  )) +
  geom_range(
    fill = "white", 
    height = 0.25
  ) +
  geom_range(
    data = sod1_201_cds
  ) + 
  geom_intron(
    data = to_intron(sod1_201_exons, "transcript_name")
  ) + 
  geom_junction(
    data = sod1_junctions,
    junction.y.max = 0.5
  ) +
  geom_junction_label_repel(
    data = sod1_junctions,
    aes(label = round(mean_count, 2)),
    junction.y.max = 0.5
  )

dzhang32 avatar Nov 26 '22 13:11 dzhang32

Hi,

Thanks for your feedback!

I've tried it again, and the same issue has happened. I copied the code directly from your email this time, and the CDS's are definitely there. The plot is attached.

Do you think it could be to do with versions of ggplot2? I get this warning message: Using the size aesthetic in this geom was deprecated in ggplot2 3.4.0. Please use linewidth in the default_aes field and elsewhere instead. It's interesting because this code doesn't use 'size' or 'linewidth', but perhaps the problem is ggplot anyway?

Thanks again, Srishti [image: image.png]

On Sat, Nov 26, 2022 at 1:22 PM David Zhang @.***> wrote:

Hi - thanks for your feedback on ggtranscript!

I'm unable to reproduce this issue and can't spot anything wrong in the code or environment. The grey boxes representing the CDS (which should be generated by geom_range(data = sod1_201_cds)) are also missing from your plot - are you sure this is the plot generated by your attached code?

On a fresh R session, could you try running the code below and let me know if the outputted plot still has the geom_junction_label_repel issue:

library(ggtranscript) library(ggplot2) library(dplyr) library(magrittr)

sod1_exons <- sod1_annotation %>% dplyr::filter(type == "exon") sod1_cds <- sod1_annotation %>% dplyr::filter(type == "CDS")

sod1_201_exons <- sod1_exons %>% dplyr::filter(transcript_name == "SOD1-201") sod1_201_cds <- sod1_cds %>% dplyr::filter(transcript_name == "SOD1-201") sod1_202_exons <- sod1_exons %>% dplyr::filter(transcript_name == "SOD1-202") sod1_202_cds <- sod1_cds %>% dplyr::filter(transcript_name == "SOD1-202")

sod1_junctions <- sod1_junctions %>% dplyr::mutate(transcript_name = "SOD1-201")

sod1_201_exons %>% ggplot(aes( xstart = start, xend = end, y = transcript_name )) + geom_range( fill = "white", height = 0.25 ) + geom_range( data = sod1_201_cds ) + geom_intron( data = to_intron(sod1_201_exons, "transcript_name") ) + geom_junction( data = sod1_junctions, junction.y.max = 0.5 ) + geom_junction_label_repel( data = sod1_junctions, aes(label = round(mean_count, 2)), junction.y.max = 0.5 )

— Reply to this email directly, view it on GitHub https://github.com/dzhang32/ggtranscript/issues/8#issuecomment-1328045715, or unsubscribe https://github.com/notifications/unsubscribe-auth/AWTHDPFG7RSQFCK76TW3RMDWKIFHTANCNFSM6AAAAAASBGDVCY . You are receiving this because you authored the thread.Message ID: @.***>

srisarya avatar Nov 29 '22 14:11 srisarya

I'm having the same issue.

davemcg avatar Feb 11 '24 16:02 davemcg