Hi everyone,
I just downloaded the EnhancedVolcano package and I was trying to create my custom color scheme. The default color scheme makes DEGs that are above and below the FCCutoff the same color (e.g. red). However, I would like the upregulated and downregulated DEGs to be different colors, so I followed the manual example to create a new vector:
test <- read_csv("DEG.csv") %>% as.data.frame() ## My table contains gene symbol, log2FoldChange, pvalue and padj
keyvals <- ifelse(test$log2FoldChange <= -1 & test$padj<0.01, 'royalblue', ifelse(test$log2FoldChange >=1 & test$padj<0.01, 'red2', 'black'))
I checked that my 'keyvals' vector is the same length as my 'test' table and there is a color value in every row (no 'NA'). Then when I run this
EnhancedVolcano(test, lab=test$mgi_symbol, x='log2FoldChange',y='padj', xlim=c(-10,10), pCutoff=10e-3, colCustom=keyvals)
I get the following error:
Error: Aesthetics must be either length 1 or the same as the data (20326): colour
I'm quite new to R so I'm not sure what went wrong. Any help (@ Kevin Blighe) will be much appreciated!
Hello Kevin,
Thanks for your prompt reply! Here are the output:
str(test) output: https://ibb.co/gmNLsHQ head (test) and str(keyvals) output: https://ibb.co/9qHbWJW sessionInfo() output: https://ibb.co/vJ5Ccyp
https://ibb.co/N6hxnP6 https://ibb.co/mX138ZN https://ibb.co/MkpKF1w
Sorry, I didn't know how to copy and paste all the output messages here ><
Thanks! Is
test$mgi_symbol
NA for everything? Does the plot generate if you uselab=test$row
?Hi Kevin,
'test$mgi_symbol' is not NA for everything, I do have gene symbols for some of the rows (because I only wanted to plot specific genes of interest). The plot generates no problem with the 'lab=test$mgi_symbol' and other customization as long as I don't include the 'colCustom=keyvals'. As soon as I add 'colCustom=keyvals', the error comes out :(
oh! I think that you need to also set the names of the
keyvals
vector. See the example here: https://github.com/kevinblighe/EnhancedVolcano#over-ride-colouring-scheme-with-custom-key-value-pairsAh! It works! Thanks so much Kevin! That was so careless of me >w<
Senza problemi / No problem / No hay de que / Problema nenhum