Unable to over/ride colour scheme with custom key-value pairs
1
0
Entering edit mode
@72a3efa9
Last seen 23 months ago
Sweden

Hello, I am pretty new at this and trying to colour my volcano plot based on up and down regulated genes, but when I run it it says:

Error in check_aesthetics(): ! Aesthetics must be either length 1 or the same as the data (499): colour

This is my code:

keyvals <- ifelse(p$log2FoldChange < -0.5 & p$padj > 0.05, 'darkorange',
ifelse(p$log2FoldChange > 0.5 & p$padj > 0.05, 'mediumpurple', "black"))
keyvals[is.na(keyvals)] <- 'black'
names(keyvals)[keyvals == 'darkorange'] <- 'high'
names(keyvals)[keyvals == 'black'] <- 'mid'
names(keyvals)[keyvals == 'mediumpurple'] <- 'low'


EnhancedVolcano(p,
lab = rownames(p),
x = 'FC.AD.vs.C',
y = 'padj',
xlab = bquote(~Log[2]~ 'fold change'),
pCutoff = 0.05,
FCcutoff = 0.5,
pointSize = 3.0,
labSize = 3.0,
colCustom = keyvals,
colAlpha = 3/5,
labCol = 'black',
labFace = 'bold',
parseLabels = TRUE,
legendPosition = 'right',
legendLabSize = 14,
legendIconSize = 4.0,
drawConnectors = TRUE,
arrowheads = FALSE,
widthConnectors = 0.5,
colConnectors = 'black',
gridlines.major = FALSE,
gridlines.minor = FALSE)


sessionInfo( )

R version 4.2.1 (2022-06-23)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.5.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2/Resources/lib/libRlapack.dylib

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

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

other attached packages:
[1] RColorBrewer_1.1-3     colorspace_2.0-3       EnhancedVolcano_1.14.0 ggrepel_0.9.1         
[5] ggplot2_3.3.6         

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.9       magrittr_2.0.3   tidyselect_1.1.2 munsell_0.5.0    R6_2.5.1         rlang_1.0.6     
 [7] fansi_1.0.3      dplyr_1.0.10     tools_4.2.1      grid_4.2.1       gtable_0.3.1     utf8_1.2.2      
[13] cli_3.4.1        withr_2.5.0      digest_0.6.29    tibble_3.1.8     lifecycle_1.0.2  farver_2.1.1    
[19] purrr_0.3.4      vctrs_0.4.1      glue_1.6.2       labeling_0.4.2   compiler_4.2.1   pillar_1.8.1    
[25] generics_0.1.3   scales_1.2.1     pkgconfig_2.0.3

I would appreciate any help!

EnhancedVolcano • 1.3k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 30 minutes ago
United States

The error says this:

Error in check_aesthetics(): ! Aesthetics must be either length 1 or the same as the data (499): colour

And you are providing a vector called keyvals for the color aesthetic. You should probably check to see if keyvals is a vector of length 499.

ADD COMMENT
0
Entering edit mode

Indeed, please actually check the length of keyvals - it should be the exact same as the number of rows in your p object.

ADD REPLY

Login before adding your answer.

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