Skip to content

Commit 5adccf7

Browse files
Added argument for better font size control in plotFoldChange
1 parent bac4a67 commit 5adccf7

5 files changed

Lines changed: 57 additions & 11 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: pathlinkR
22
Type: Package
33
Title: Analyze and interpret RNA-Seq results
4-
Version: 1.7.21
4+
Version: 1.7.22
55
Authors@R: c(
66
person("Travis", "Blimkie", email = "travis.m.blimkie@gmail.com", role = "cre", comment = c(ORCID = "0000-0001-8778-8627")),
77
person("Andy", "An", email = "andy@hancocklab.com", role = "aut")

R/plotFoldChange.R

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
#' `pathName`/`pathID` are mutually exclusive.
2121
#' @param manualTitle Provide your own title, and override the use of a pathway
2222
#' name the title.
23-
#' @param titleSize Font size for the title (14).
23+
#' @param fontSizes Font sizes for the elements: column title, row title,
24+
#' column names, row names, legend title, legend labels. Defaults to
25+
#' `c(13.2, 13.2, 12, 12, 10, 10)`.
2426
#' @param geneFormat Type of genes given in `genesToPlot`. Default is Ensembl
2527
#' gene IDs ("ensembl"), but can also input a vector of HGNC symbols ("hgnc").
2628
#' @param pCutoff P value cutoff, default is <0.05
@@ -128,7 +130,7 @@ plotFoldChange <- function(
128130
pathId=NA,
129131
genesToPlot=NA,
130132
manualTitle=NA,
131-
titleSize=14,
133+
fontSizes=c(13.2, 13.2, 12, 12, 10, 10),
132134
geneFormat="ensembl",
133135
pCutoff=0.05,
134136
fcCutoff=1.5,
@@ -167,6 +169,17 @@ plotFoldChange <- function(
167169
geneFormat %in% c("ensembl", "hgnc")}
168170
)
169171

172+
stopifnot("Incorrect format for 'fontSizes'" ={
173+
is(fontSizes, "numeric") & length(fontSizes) == 6
174+
})
175+
176+
sizeColTitle <- fontSizes[1]
177+
sizeRowTitle <- fontSizes[2]
178+
sizeColNames <- fontSizes[3]
179+
sizeRowNames <- fontSizes[4]
180+
sizeLegendTitle <- fontSizes[5]
181+
sizeLegendLabels <- fontSizes[6]
182+
170183
## Coerce the input
171184
if (is(inputList[[1]], "DESeqResults")) {
172185
inputListCleaned <- lapply(inputList, function(x) {
@@ -330,10 +343,11 @@ plotFoldChange <- function(
330343
heatmapLegendInfo <- .plotFoldChangeLegend(
331344
.matFC=matFC,
332345
.log2FoldChange=log2FoldChange,
333-
.cellColours=cellColours
346+
.cellColours=cellColours,
347+
.titlegp=sizeLegendTitle,
348+
.labelsgp=sizeLegendLabels
334349
)
335350

336-
337351
## If columns aren't being split
338352
if (is.na(colSplit[1])) {
339353
colSplit <- rep(NA, length(inputListCleaned))
@@ -406,7 +420,10 @@ plotFoldChange <- function(
406420
column_title=plotTitle,
407421
row_title=NULL,
408422
heatmap_legend_param=heatmapLegendInfo[[1]],
409-
column_title_gp=gpar(fontsize=titleSize),
423+
column_title_gp=gpar(fontsize=sizeColTitle),
424+
row_title_gp=gpar(fontsize=sizeRowTitle),
425+
column_names_gp=gpar(fontsize=sizeColNames),
426+
row_names_gp=gpar(fontsize=sizeRowNames),
410427
row_split=rowSplit,
411428
column_split=colSplit,
412429
cluster_columns=clusterColumns,
@@ -425,6 +442,8 @@ plotFoldChange <- function(
425442
#' @param .matFC Matrix of fold change values
426443
#' @param .log2FoldChange Boolean denoting if values will be in log2
427444
#' @param .cellColours Colours for fold change values
445+
#' @param .titlegp Font size for the title of the legend
446+
#' @param .labelsgp Font size for the labels of the legend
428447
#'
429448
#' @return A list containing heatmap legend parameters and colour function
430449
#'
@@ -435,10 +454,12 @@ plotFoldChange <- function(
435454
#'
436455
#' @seealso <https://github.com/hancockinformatics/pathlinkR>
437456
#'
438-
.plotFoldChangeLegend <- function(.matFC, .log2FoldChange, .cellColours) {
457+
.plotFoldChangeLegend <- function(.matFC, .log2FoldChange, .cellColours, .titlegp, .labelsgp) {
439458

440459
parameters <- list(
441-
title=ifelse(.log2FoldChange, "Log2 fold\nchange", "Fold change")
460+
title=ifelse(.log2FoldChange, "Log2 fold\nchange", "Fold change"),
461+
title_gp=gpar(fontsize=.titlegp),
462+
labels_gp=gpar(fontsize=.labelsgp)
442463
)
443464

444465
limit <- ceiling(max(abs(.matFC)))

man/dot-plotFoldChangeLegend.Rd

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plotFoldChange.Rd

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-plotFoldChange.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,16 @@ test_that("argument 'returnData' is working.", {
2727
"list"
2828
)
2929
})
30+
31+
test_that("fold change heatmaps are working with custom font sizes", {
32+
data("exampleDESeqResults")
33+
34+
expect_no_error(
35+
plotFoldChange(
36+
inputList=exampleDESeqResults,
37+
pathName="PD-1 signaling",
38+
hideNonsigFC=FALSE,
39+
clusterColumns=TRUE
40+
)
41+
)
42+
})

0 commit comments

Comments
 (0)