edit y axis scale in errBarchart?
1
0
Entering edit mode
arustagi • 0
@5f20482a
Last seen 6 days ago
United States

Hello,

I'm enjoying aspects of this package but when I try to visualize the results using errBarchart() the y axis defaults to minimum of 0 and maximum of 3 for all samples or detectors, such that anything with a fold change above 3 just maxes out the graph. I cannot figure out how to modify this behavior of the errBarchart function. I know it is calling lattice::barchart but exactly how is a mystery to me; I cannot figure out how to view the source code of errBarchart to see how I can use scales or ylim to adjust.

sessionInfo() R version 4.4.1 (2024-06-14) Platform: aarch64-apple-darwin20 Running under: macOS 15.0.1

Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0

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

time zone: America/Los_Angeles tzcode source: internal

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

other attached packages: [1] ggplot2_3.5.1 ddCt_1.60.0

loaded via a namespace (and not attached): [1] vctrs_0.6.5 cli_3.6.3 knitr_1.48 rlang_1.1.4 xfun_0.48
[6] generics_0.1.3 xtable_1.8-4 glue_1.8.0 colorspace_2.1-1 htmltools_0.5.8.1
[11] fansi_1.0.6 scales_1.3.0 rmarkdown_2.28 Biobase_2.64.0 grid_4.4.1
[16] tibble_3.2.1 evaluate_1.0.1 munsell_0.5.1 fastmap_1.2.0 yaml_2.3.10
[21] lifecycle_1.0.4 compiler_4.4.1 dplyr_1.1.4 RColorBrewer_1.1-3 pkgconfig_2.0.3
[26] rstudioapi_0.17.1 lattice_0.22-6 digest_0.6.37 R6_2.5.1 tidyselect_1.2.1
[31] utf8_1.2.4 pillar_1.9.0 magrittr_2.0.3 withr_3.0.2 tools_4.4.1
[36] gtable_0.3.6 BiocGenerics_0.50.0

ddCt • 166 views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 5 hours ago
United States

It's an S4 method.

> errBarchart
standardGeneric for "errBarchart" defined from package "ddCt"

function (object, by, ...) 
standardGeneric("errBarchart")
<bytecode: 0x0000016d025959c8>
<environment: 0x0000016d02592068>
Methods may be defined for arguments: object, by
Use  showMethods(errBarchart)  for currently available ones.

And you should note that the message at the bottom gives you a hint!

> showMethods(errBarchart)
Function: errBarchart (package ddCt)
object="ddCtExpression", by="character"
object="ddCtExpression", by="missing"

But that's pretty boring, and no helpful messages! If you search around, you will find that there are two choices for showing the function body. Use the 'includeDefs' argument to showMethods (useful if there aren't too many things that it dispatches on), or selectMethod. Let's try both.

> showMethods(errBarchart, includeDefs = TRUE)
Function: errBarchart (package ddCt)
object="ddCtExpression", by="character"
function (object, by, ...) 
{
    res <- elist(object)
    ddCtErrBarchart(res, by = by, ...)
}


object="ddCtExpression", by="missing"
function (object, by, ...) 
{
    res <- elist(object)
    ddCtErrBarchart(res, by = "Sample", ...)
}

> selectMethod(errBarchart, c(object="ddCtExpression", by="character"))
Method Definition:

function (object, by, ...) 
{
    res <- elist(object)
    ddCtErrBarchart(res, by = by, ...)
}
<bytecode: 0x0000016d02598e68>
<environment: namespace:ddCt>

Signatures:
        object           by         
target  "ddCtExpression" "character"
defined "ddCtExpression" "character"

So now we know that it's just passing data to another function called ddCtErrBarchart. Let's look at that.

> ddCtErrBarchart
Error: object 'ddCtErrBarchart' not found

It seems unlikely that the function doesn't exist (it does exist!), so why can't it be found? It's because the function is not exported from the NAMESPACE for ddCt, which is good, because you don't want to pollute the search path with extraneous functions. But how to get the function?

> getAnywhere(ddCtErrBarchart)
A single object matching 'ddCtErrBarchart' was found
It was found in the following places
  namespace:ddCt
with value

function (x, by = c("Sample", "Detector"), thr = 3, ylab = "Expression fold change", 
    cols = brewer.pal(12, "Set3"), round = 0, outText = TRUE, 
    rot = 45, parameter = new("errBarchartParameter"), detector.levels = levels(factor(as.character(x$Detector))), 
    sample.levels = levels(factor(as.character(x$Sample))), ...) 
{
    if (all(is.na(x$exprs))) 
        stop("All expressions are NA!\n")
    x$Sample <- factor(as.character(x$Sample), sample.levels)
    x$Detector <- factor(as.character(x$Detector), detector.levels)
    by <- match.arg(by, choices = c("Sample", "Detector"))
    if (by == "Sample") {
        formula <- as.formula("exprs + level.err ~ Sample | Detector")
    }
    else {
        formula <- as.formula("exprs + level.err ~ Detector | Sample")
    }
    xlab <- by
    barchart(formula, data = x, scales = list(x = list(rot = rot), 
        y = list(alternating = 1, at = seq(0, thr, 0.5))), ylim = c(0, 
        thr * 1.1), panel = function(x, y, ...) panel.ddCtErrBarchart(x = x, 
        y = y, thr = thr, round = round, outText = outText, parameter = parameter, 
        ...), xlab = xlab, ylab = ylab, col = cols, ...)
}
<bytecode: 0x0000016d03ab7938>
<environment: namespace:ddCt>

Note at the bottom that it says the namespace for the function, so (if you already know where it lives) you can access using the ::: function

> ddCt:::ddCtErrBarchart
function (x, by = c("Sample", "Detector"), thr = 3, ylab = "Expression fold change", 
    cols = brewer.pal(12, "Set3"), round = 0, outText = TRUE, 
    rot = 45, parameter = new("errBarchartParameter"), detector.levels = levels(factor(as.character(x$Detector))), 
    sample.levels = levels(factor(as.character(x$Sample))), ...) 
{
    if (all(is.na(x$exprs))) 
        stop("All expressions are NA!\n")
    x$Sample <- factor(as.character(x$Sample), sample.levels)
    x$Detector <- factor(as.character(x$Detector), detector.levels)
    by <- match.arg(by, choices = c("Sample", "Detector"))
    if (by == "Sample") {
        formula <- as.formula("exprs + level.err ~ Sample | Detector")
    }
    else {
        formula <- as.formula("exprs + level.err ~ Detector | Sample")
    }
    xlab <- by
    barchart(formula, data = x, scales = list(x = list(rot = rot), 
        y = list(alternating = 1, at = seq(0, thr, 0.5))), ylim = c(0, 
        thr * 1.1), panel = function(x, y, ...) panel.ddCtErrBarchart(x = x, 
        y = y, thr = thr, round = round, outText = outText, parameter = parameter, 
        ...), xlab = xlab, ylab = ylab, col = cols, ...)
}
<bytecode: 0x0000016d03ab7938>
<environment: namespace:ddCt>

Anyway, errBarchart allows you to pass arbitrary arguments down to subsequent functions via the ... argument, and you can see that the 'thr' argument controls the vertical axis limits, so you can just add 'thr = 4' to your call and you will then get a wider range for the vertical axis.

Login before adding your answer.

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