Browse code

Renamed variable "Group" (expression groups, 1-12) to "Category"

almeidasilvaf authored on 02/11/2023 18:19:11
Showing 9 changed files

... ...
@@ -13,7 +13,7 @@ Authors@R:
13 13
         ),
14 14
         person(
15 15
             given = "Lucas",
16
-            family = "Prost",
16
+            family = "Prost-Boxoen",
17 17
             role = "aut",
18 18
             comment = c(ORCID = "0000-0003-2779-9097")
19 19
         ),
... ...
@@ -7,7 +7,7 @@
7 7
 #' @return A data with the following variables:
8 8
 #' \describe{
9 9
 #'   \item{Gene}{Character, gene ID.}
10
-#'   \item{Group}{Factor, expression group. Group names are numbers from
10
+#'   \item{Category}{Factor, expression group. Category names are numbers from
11 11
 #'   1 to 12.}
12 12
 #'   \item{Class}{Factor, expression group class. One of "UP" (transgressive
13 13
 #'   up-regulation), "DOWN" (transgressive down-regulation), 
... ...
@@ -52,7 +52,7 @@ expression_partitioning <- function(deg_list) {
52 52
             "unchanged-down-down",
53 53
             "up-down-down"
54 54
         ),
55
-        Group = factor(c(1:12), levels = 1:12),
55
+        Category = factor(c(1:12), levels = 1:12),
56 56
         Class = factor(cl, levels = c("UP", "DOWN", "ADD", "ELD_P1", "ELD_P2"))
57 57
     )
58 58
 
... ...
@@ -74,9 +74,9 @@ expression_partitioning <- function(deg_list) {
74 74
     )
75 75
     
76 76
     # Combine classification data frame with log2foldchange
77
-    class_df <- merge(classified_genes[, c("Gene", "Group", "Class")], log2fc_df)
78
-    class_df <- class_df[!is.na(class_df$Group), ]
79
-    class_df <- class_df[order(class_df$Group), ]
77
+    class_df <- merge(classified_genes[, c("Gene", "Category", "Class")], log2fc_df)
78
+    class_df <- class_df[!is.na(class_df$Category), ]
79
+    class_df <- class_df[order(class_df$Category), ]
80 80
     
81 81
     rownames(class_df) <- NULL
82 82
     
... ...
@@ -179,8 +179,8 @@ get_deg_summary <- function(deg_list) {
179 179
 #' as returned by \code{expression_partitioning()}.
180 180
 #' @param palette A character vector with the color palette to use.
181 181
 #' @param group_by Character indicating the name of the variable 
182
-#' in \strong{partition_table} to use to group genes. One of "Group" or
183
-#' "Class". Default: "Group".
182
+#' in \strong{partition_table} to use to group genes. One of "Category" or
183
+#' "Class". Default: "Category".
184 184
 #'
185 185
 #' @return A ggplot object with a scatterplot.
186 186
 #' 
... ...
@@ -189,7 +189,9 @@ get_deg_summary <- function(deg_list) {
189 189
 #' @importFrom rlang .data
190 190
 #' @noRd
191 191
 #' 
192
-partition_scatterplot <- function(partition_table, palette, group_by = "Group") {
192
+partition_scatterplot <- function(
193
+        partition_table, palette, group_by = "Category"
194
+) {
193 195
     
194 196
     p_scatter <- ggplot(
195 197
         partition_table, aes(x = .data$lFC_F1_vs_P1, y = .data$lFC_F1_vs_P2)
... ...
@@ -223,8 +225,8 @@ partition_scatterplot <- function(partition_table, palette, group_by = "Group")
223 225
 #' @param add_n Logical indicating whether to include number of genes in each
224 226
 #' group or not. Default: TRUE.
225 227
 #' @param group_by Character indicating the name of the variable 
226
-#' in \strong{partition_table} to use to group genes. One of "Group" or
227
-#' "Class". Default: "Group".
228
+#' in \strong{partition_table} to use to group genes. One of "Category" or
229
+#' "Class". Default: "Category".
228 230
 #'
229 231
 #' @return A list of ggplot objects with line plots.
230 232
 #' 
... ...
@@ -234,12 +236,12 @@ partition_scatterplot <- function(partition_table, palette, group_by = "Group")
234 236
 #' @noRd
235 237
 #' 
236 238
 partition_lineplots <- function(
237
-        partition_table, palette, add_n = TRUE, group_by = "Group"
239
+        partition_table, palette, add_n = TRUE, group_by = "Category"
238 240
 ) {
239 241
     
240 242
     # Data frame of point coordinates for each group
241 243
     pline_data <- data.frame(
242
-        Group = factor(rep(1:12, each = 3)),
244
+        Category = factor(rep(1:12, each = 3)),
243 245
         Class = factor(
244 246
             rep(c(
245 247
                 "ADD", "ELD_P1", "DOWN", "ELD_P2", "UP", "UP", 
... ...
@@ -267,7 +269,7 @@ partition_lineplots <- function(
267 269
     pline_data <- split(pline_data, pline_data[[group_by]])
268 270
     
269 271
     ## Number of genes per level of `group_by`
270
-    n <- as.numeric(table(partition_table$Group))
272
+    n <- as.numeric(table(partition_table$Category))
271 273
     
272 274
     p_line <- lapply(seq_along(pline_data), function(x) {
273 275
         
... ...
@@ -286,7 +288,7 @@ partition_lineplots <- function(
286 288
             ) +
287 289
             ylim(c(0, 4))
288 290
         
289
-        if(group_by == "Class") { p <- p + facet_wrap("Group") }
291
+        if(group_by == "Class") { p <- p + facet_wrap("Category") }
290 292
         
291 293
         return(p)
292 294
     })
... ...
@@ -88,11 +88,11 @@ plot_expression_triangle <- function(
88 88
 #' @param partition_table A data frame with genes per expression partition
89 89
 #' as returned by \code{expression_partitioning()}.
90 90
 #' @param group_by Character indicating the name of the variable 
91
-#' in \strong{partition_table} to use to group genes. One of "Group" or
92
-#' "Class". Default: "Group".
91
+#' in \strong{partition_table} to use to group genes. One of "Category" or
92
+#' "Class". Default: "Category".
93 93
 #' @param palette Character vector with color names to be used for each level
94 94
 #' of the variable specified in \strong{group_by}. 
95
-#' If \strong{group_by = "Group"}, this must be a vector of length 12.
95
+#' If \strong{group_by = "Category"}, this must be a vector of length 12.
96 96
 #' If \strong{group_by = "Class"}, this must be a vector of length 5.
97 97
 #' If NULL, a default color palette will be used.
98 98
 #'
... ...
@@ -108,7 +108,7 @@ plot_expression_triangle <- function(
108 108
 #' partition_table <- expression_partitioning(deg_list)
109 109
 #' plot_expression_partitions(partition_table)
110 110
 plot_expression_partitions <- function(
111
-        partition_table, group_by = "Group", palette = NULL
111
+        partition_table, group_by = "Category", palette = NULL
112 112
 ) {
113 113
     
114 114
     pdata <- partition_table
... ...
@@ -158,11 +158,11 @@ plot_expression_partitions <- function(
158 158
 #' @param partition_table A data frame with genes per expression partition
159 159
 #' as returned by \code{expression_partitioning()}.
160 160
 #' @param group_by Character indicating the name of the variable 
161
-#' in \strong{partition_table} to use to group genes. One of "Group" or
162
-#' "Class". Default: "Group".
161
+#' in \strong{partition_table} to use to group genes. One of "Category" or
162
+#' "Class". Default: "Category".
163 163
 #' @param palette Character vector with color names to be used for each level
164 164
 #' of the variable specified in \strong{group_by}. 
165
-#' If \strong{group_by = "Group"}, this must be a vector of length 12.
165
+#' If \strong{group_by = "Category"}, this must be a vector of length 12.
166 166
 #' If \strong{group_by = "Class"}, this must be a vector of length 5.
167 167
 #' If NULL, a default color palette will be used.
168 168
 #' 
... ...
@@ -178,7 +178,7 @@ plot_expression_partitions <- function(
178 178
 #' partition_table <- expression_partitioning(deg_list)
179 179
 #' plot_partition_frequencies(partition_table)
180 180
 plot_partition_frequencies <- function(
181
-        partition_table, group_by = "Group", palette = NULL
181
+        partition_table, group_by = "Category", palette = NULL
182 182
 ) {
183 183
     
184 184
     # Define color palette
... ...
@@ -189,21 +189,21 @@ plot_partition_frequencies <- function(
189 189
     # Get barplot data
190 190
     freqs <- table(partition_table[[group_by]])
191 191
     freq_df <- data.frame(
192
-        Group = factor(names(freqs), levels = names(freqs)), 
192
+        Category = factor(names(freqs), levels = names(freqs)), 
193 193
         N = as.numeric(freqs)
194 194
     )
195 195
     freq_df$Perc <- paste0(round((freq_df$N / sum(freq_df$N)) * 100, 2), "%")
196 196
     ymax <- round(max(freq_df$N) + mean(freq_df$N), -2)
197 197
     
198 198
     # Create barplot
199
-    p_bar <- ggplot(freq_df, aes(x = .data$Group, y = .data$N)) +
199
+    p_bar <- ggplot(freq_df, aes(x = .data$Category, y = .data$N)) +
200 200
         geom_bar(fill = pal, color = "gray20", stat = "identity") +
201 201
         geom_text(aes(label = .data$Perc), hjust = -0.2) +
202 202
         theme_bw() +
203 203
         scale_y_continuous(limits = c(0, ymax), expand = c(0, 0)) +
204 204
         theme(plot.subtitle = element_text(size = 13)) +
205 205
         labs(y = "Count", subtitle = "Frequency of genes per partition") +
206
-        scale_x_discrete(limits = rev(levels(freq_df$Group))) +
206
+        scale_x_discrete(limits = rev(levels(freq_df$Category))) +
207 207
         coord_flip() 
208 208
     
209 209
     
... ...
@@ -213,7 +213,7 @@ plot_partition_frequencies <- function(
213 213
     )
214 214
     
215 215
     # Combine plots
216
-    ncols <- ifelse(group_by == "Group", 2, 1)
216
+    ncols <- ifelse(group_by == "Category", 2, 1)
217 217
     p_final <- wrap_plots(
218 218
         wrap_plots(p_line, ncol = ncols) & 
219 219
             theme(plot.margin = unit(rep(1, 4), "pt")),
... ...
@@ -14,7 +14,7 @@ differentially expressed genes as returned by \code{get_deg_list()}.}
14 14
 A data with the following variables:
15 15
 \describe{
16 16
 \item{Gene}{Character, gene ID.}
17
-\item{Group}{Factor, expression group. Group names are numbers from
17
+\item{Category}{Factor, expression group. Category names are numbers from
18 18
 1 to 12.}
19 19
 \item{Class}{Factor, expression group class. One of "UP" (transgressive
20 20
 up-regulation), "DOWN" (transgressive down-regulation),
... ...
@@ -4,19 +4,23 @@
4 4
 \alias{plot_expression_partitions}
5 5
 \title{Plot expression partitions}
6 6
 \usage{
7
-plot_expression_partitions(partition_table, group_by = "Group", palette = NULL)
7
+plot_expression_partitions(
8
+  partition_table,
9
+  group_by = "Category",
10
+  palette = NULL
11
+)
8 12
 }
9 13
 \arguments{
10 14
 \item{partition_table}{A data frame with genes per expression partition
11 15
 as returned by \code{expression_partitioning()}.}
12 16
 
13 17
 \item{group_by}{Character indicating the name of the variable
14
-in \strong{partition_table} to use to group genes. One of "Group" or
15
-"Class". Default: "Group".}
18
+in \strong{partition_table} to use to group genes. One of "Category" or
19
+"Class". Default: "Category".}
16 20
 
17 21
 \item{palette}{Character vector with color names to be used for each level
18 22
 of the variable specified in \strong{group_by}.
19
-If \strong{group_by = "Group"}, this must be a vector of length 12.
23
+If \strong{group_by = "Category"}, this must be a vector of length 12.
20 24
 If \strong{group_by = "Class"}, this must be a vector of length 5.
21 25
 If NULL, a default color palette will be used.}
22 26
 }
... ...
@@ -4,19 +4,23 @@
4 4
 \alias{plot_partition_frequencies}
5 5
 \title{Plot a barplot of gene frequencies per expression partition}
6 6
 \usage{
7
-plot_partition_frequencies(partition_table, group_by = "Group", palette = NULL)
7
+plot_partition_frequencies(
8
+  partition_table,
9
+  group_by = "Category",
10
+  palette = NULL
11
+)
8 12
 }
9 13
 \arguments{
10 14
 \item{partition_table}{A data frame with genes per expression partition
11 15
 as returned by \code{expression_partitioning()}.}
12 16
 
13 17
 \item{group_by}{Character indicating the name of the variable
14
-in \strong{partition_table} to use to group genes. One of "Group" or
15
-"Class". Default: "Group".}
18
+in \strong{partition_table} to use to group genes. One of "Category" or
19
+"Class". Default: "Category".}
16 20
 
17 21
 \item{palette}{Character vector with color names to be used for each level
18 22
 of the variable specified in \strong{group_by}.
19
-If \strong{group_by = "Group"}, this must be a vector of length 12.
23
+If \strong{group_by = "Category"}, this must be a vector of length 12.
20 24
 If \strong{group_by = "Class"}, this must be a vector of length 5.
21 25
 If NULL, a default color palette will be used.}
22 26
 }
... ...
@@ -68,7 +68,7 @@ test_that("get_deg_summary() returns a data frame with DE summary", {
68 68
 test_that("partition_scatterplot() creates a scatterplot", {
69 69
     
70 70
     p1 <- partition_scatterplot(partition_table, palette_class, "Class")
71
-    p2 <- partition_scatterplot(partition_table, palette_group, "Group")
71
+    p2 <- partition_scatterplot(partition_table, palette_group, "Category")
72 72
     
73 73
     expect_true(is(p1, "ggplot"))
74 74
 })
... ...
@@ -24,7 +24,7 @@ test_that("plot_expression_triangle() returns a ggplot object", {
24 24
 
25 25
 test_that("plot_expression_partitions() returns a multi-panel ggplot", {
26 26
     
27
-    p1 <- plot_expression_partitions(ptable, group_by = "Group")
27
+    p1 <- plot_expression_partitions(ptable, group_by = "Category")
28 28
     p2 <- plot_expression_partitions(ptable, group_by = "Class")
29 29
     
30 30
     expect_true(is(p1, "ggplot"))
... ...
@@ -33,7 +33,7 @@ test_that("plot_expression_partitions() returns a multi-panel ggplot", {
33 33
 
34 34
 test_that("plot_partition_frequencies() returns a multi-panel ggplot", {
35 35
     
36
-    p1 <- plot_partition_frequencies(ptable, group_by = "Group")
36
+    p1 <- plot_partition_frequencies(ptable, group_by = "Category")
37 37
     p2 <- plot_partition_frequencies(ptable, group_by = "Class")
38 38
     
39 39
     expect_true(is(p1, "ggplot"))