Browse code

Changed genomic coordinates to automatic scale with units.

Shians authored on 18/07/2022 06:29:56
Showing 5 changed files

... ...
@@ -42,7 +42,7 @@ Imports:
42 42
     rlang,
43 43
     RSQLite,
44 44
     Rsamtools,
45
-    scales,
45
+    scales (>= 1.2.0),
46 46
     scico,
47 47
     stats,
48 48
     stringr,
... ...
@@ -15,6 +15,7 @@
15 15
 #' @importFrom glue glue
16 16
 #' @importFrom assertthat assert_that is.readable is.writeable is.dir is.string
17 17
 #' @importFrom stringr str_extract
18
+#' @importFrom scales label_number cut_si
18 19
 #' @importFrom readr cols col_character col_integer col_logical col_double
19 20
 #' @importFrom tibble tibble as_tibble add_column
20 21
 #' @importFrom withr defer
... ...
@@ -133,7 +133,8 @@ setMethod("plot_gene", signature(x = "NanoMethResult", gene = "character"),
133 133
     )
134 134
     p1 <- p1 + ggplot2::scale_x_continuous(
135 135
             limits = c(plot_left, plot_right),
136
-            expand = ggplot2::expansion()
136
+            expand = ggplot2::expansion(),
137
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))
137 138
         )
138 139
 
139 140
 
... ...
@@ -144,7 +145,8 @@ setMethod("plot_gene", signature(x = "NanoMethResult", gene = "character"),
144 145
         p2 <- plot_gene_annotation(exons_anno, plot_left, plot_right) +
145 146
             ggplot2::scale_x_continuous(
146 147
                 limits = c(plot_left, plot_right),
147
-                expand = ggplot2::expansion()
148
+                expand = ggplot2::expansion(),
149
+                labels = scales::label_number(scale_cut = scales::cut_si("b"))
148 150
             )
149 151
 
150 152
         n_unique <- function(x) { length(unique(x)) }
... ...
@@ -164,7 +166,8 @@ setMethod("plot_gene", signature(x = "NanoMethResult", gene = "character"),
164 166
         ) +
165 167
             ggplot2::scale_x_continuous(
166 168
                 limits = c(plot_left, plot_right),
167
-                expand = ggplot2::expansion())
169
+                expand = ggplot2::expansion(),
170
+                labels = scales::label_number(scale_cut = scales::cut_si("b")))
168 171
 
169 172
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))
170 173
     }
... ...
@@ -102,7 +102,10 @@ plot_methylation_internal <- function(
102 102
         ggplot2::geom_rug(aes(col = NULL), sides = "b") +
103 103
         ggplot2::ggtitle(title) +
104 104
         ggplot2::xlab(chr) +
105
-        ggplot2::scale_y_continuous(limits = c(0, 1), expand = ggplot2::expansion()) +
105
+        ggplot2::scale_y_continuous(
106
+            limits = c(0, 1),
107
+            expand = ggplot2::expansion(),
108
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))) +
106 109
         palette_col +
107 110
         ggplot2::theme_bw()
108 111
 }
... ...
@@ -199,13 +199,15 @@ setMethod("plot_region",
199 199
     ) +
200 200
         ggplot2::scale_x_continuous(
201 201
             limits = xlim,
202
-            expand = ggplot2::expansion()
202
+            expand = ggplot2::expansion(),
203
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))
203 204
         )
204 205
 
205 206
     p2 <- plot_gene_annotation(exons_anno, xlim[1], xlim[2]) +
206 207
         ggplot2::scale_x_continuous(
207 208
             limits = xlim,
208
-            expand = ggplot2::expansion()
209
+            expand = ggplot2::expansion(),
210
+            labels = scales::label_number(scale_cut = scales::cut_si("b"))
209 211
         )
210 212
 
211 213
     anno_height <- attr(p2, "plot_height")
... ...
@@ -217,7 +219,8 @@ setMethod("plot_region",
217 219
         p_heatmap <- plot_region_heatmap(x, chr, start, end, window_prop = window_prop) +
218 220
             ggplot2::scale_x_continuous(
219 221
                 limits = xlim,
220
-                expand = ggplot2::expansion()
222
+                expand = ggplot2::expansion(),
223
+                labels = scales::label_number(scale_cut = scales::cut_si("b"))
221 224
             )
222 225
 
223 226
         p_out <- stack_plots(p_out, ggrastr::rasterise(p_heatmap, dpi = 300))