sneumann / xcms

This is the git repository matching the Bioconductor package xcms: LC/MS and GC/MS Data Analysis
Other
183 stars 80 forks source link

what meaning【group_colors <- paste(brewer.pal(3, "Set1")[1:2], "60")】 in xcms?Why is the error reported? #537

Closed nyj123 closed 3 years ago

nyj123 commented 3 years ago

` library(xcms)

library(faahKO) library(RColorBrewer) library(pander) library(magrittr) library(pheatmap) library(SummarizedExperiment) cdfs <- dir(system.file("cdf", package = "faahKO"), full.names = TRUE,

  • recursive = TRUE)[c(1, 2, 5, 6, 7, 8, 11, 12)] pd <- data.frame(sample_name = sub(basename(cdfs), pattern = ".CDF",
  • replacement = "", fixed = TRUE),
  • sample_group = c(rep("KO",4), rep("WT", 4)),
  • stringsAsFactors = FALSE) raw_data <- readMSData(files = cdfs, pdata = new("NAnnotatedDataFrame", pd),
  • mode = "onDisk") Polarity can not be extracted from netCDF files, please set manually the polarity with the 'polarity' method. raw_data <- filterRt(raw_data, c(2500, 3500)) head(rtime(raw_data)) F1.S0001 F1.S0002 F1.S0003 F1.S0004 F1.S0005 F1.S0006 2501.378 2502.943 2504.508 2506.073 2507.638 2509.203 mzs <- mz(raw_data) Warning messages: 1: In serialize(data, node$con) : 载入时'package:stats'可能无用 2: In serialize(data, node$con) : 载入时'package:stats'可能无用 mzs_by_file <- split(mzs, f = fromFile(raw_data)) length(mzs_by_file) [1] 8 bpis <- chromatogram(raw_data, aggregationFun = "max")

group_colors error:not found 'group_colors' names(group_colors) <- c("KO", "WT") Error in names(group_colors) <- c("KO", "WT") : 找不到对象'group_colors' plot(bpis, col = group_colors[raw_data$sample_group]) Error in .plotChromatogramList(x[i, , drop = TRUE], col = col, lty = lty, : not found 'group_colors'`

jorainer commented 3 years ago

The variable group_colors in this code is assumed to define a color for each group. To me it seems that in your code you are missing the line in which group_colors is defined, such as group_colors <- c("red", "blue").

jorainer commented 3 years ago

Seems that the original line was:

group_colors <- paste(brewer.pal(3, "Set1")[1:2], "60")

What this does is: get 2 colors from the "Set" color palette (brewer.pal(3, "Set1")[1, 2]) and append the value "60" to these (brewer.pal returns colors in html notion, e.g. "#ffceff", by adding the value 60 to this the color becomes slightly transparent). Use display.brewer.all() to show all available colors defined by the RColorBrewer R package.

Please have also a look at the help of the RColorBrewer R package for more information.

I'm closing this issue now. Feel free to reopen if needed.