Hi,
I am attempting to highlight a number of genes that intersect with a list of EMT genes I have.
When I run the below, any genes that are not EMT genes disappear.. How can I fix this?
top20padj <- head(res.smIHW.cp1df.rmNA.ord$symbol, n=20)
topLFCgenes <- res.smIHW.cp1df.rmNA.ord[order(-abs(res.smIHW.cp1df.rmNA.ord$shrunkLFC)), ]
top20LFCgenes <- head(topLFCgenes$symbol, n=20)
# define genes that will show as shape 17
VolcanoEMTgenes <- as.vector(EMTgenes$`intersect(EMTdbgenes$GeneSymbol, res.smIHW.cp1df.rmNA.sig$symbol)`)
# create custom key-value pairs for defined genes
# this can be achieved with ifelse statements
keyvals.shape <- ifelse(res.smIHW.cp1df.rmNA.ord$symbol %in% VolcanoEMTgenes, 17, 19)
keyvals.shape[is.na(keyvals.shape)] <- 19
names(keyvals.shape)[keyvals.shape == 17] <- 'EMT genes'
library(EnhancedVolcano)
EnhancedVolcano(res.smIHW.cp1df.rmNA.ord,
lab = res.smIHW.cp1df.rmNA.ord$symbol,
x = 'shrunkLFC',
y = 'padj',
title = '',
subtitle = '',
pCutoff = .05,
FCcutoff = 2,
pointSize = 3.0,
labSize = 4.0,
legendLabels=c('Not sig.','Log2 FC','p-value',
'p-value & Log2 FC'),
selectLab = c(top20LFCgenes, top20padj),
shapeCustom = keyvals.shape,
drawConnectors = TRUE,
widthConnectors = 0.2,
colConnectors = 'grey30')
Hi Kevin,
Many thanks for your quick response. Your comments have fixed my issue.
I am however wondering if there is a way to bring these EMT genes to the front? And can I also simultaneously change the colour of these EMT genes without disrupting the colour scheme of LFC/pvalue/NS genes?
Many thanks,
Nathan
This can be done by re-ordering your input data-frame such that these genes are positioned at the end, meaning that they will be plot last. This has to be done manually, unfortunately.
For this, you can try one of the new 'highligthing' features (for now, only available in the Development and GitHub versions), but it may not give you what you want, in which case you may have to manually encode the colour scheme too..
Hi Kevin,
Many thanks. I have tried to do as you say and reorder the original dataframe and then attempted to manually encode the colour scheme. However unfortunatly it appears to not be following what I coded.
I wonder if you would be able to easier spot the issue?
I have included the output I get in the link: https://ibb.co/Yfnc3PV
Sorry, yes, this is getting complex, isn't it.
For the default colour scheme, in the main code, what I'm doing is:
[ source: https://github.com/kevinblighe/EnhancedVolcano/blob/master/R/EnhancedVolcano.R#L262-L269 ]
Perhaps following that (but replacing with the colour names) would be easier, in this case - the order of these commands is critical for it to work. The following mappings are:
Then, do the final part,
ifelse(EMTdbgenes.ord$symbol %in% VolcanoEMTgenes & abs(EMTdbgenes.ord$shrunkLFC) >= 0
, as a separate command.The legend position would also work better on the left or right, as there is not enough room horizontally.
You may also try not setting
legendLabels
to see how the function behaves, and then setting it again (it will require 5 values I think).Hi Kevin,
Thank you for your continued responses. Im not sure I completely follow ( I consider myself still a novic at this)
Are you meaning something like this?
I get the error 'Error: Aesthetics must be either length 1 or the same as the data (26242): colour'
perhaps its an easy fix?
Oh no, I was just providing a sort of template. In place of
EMTdbgenes.ord$Sig
, you would havekeyvals.colour
. However, you'd have to start off with:..and then proceed with:
Ah I see
So how can I avoid then overiding these colours with the ifelse statement?
to confirm, I just want to overwite the colour of the EMT genes black.
I am not sure what you mean. The first 4 lines of your code account for every variable (gene) in your data. If you want to add an additional colour for EMT genes, then, by default, this will over-ride some of the original colours, and add a new [fifth] colour.
Perhaps you want some other way to do this, but your are already using a different shape for these EMT genes. There are a few suggestions in the vignette from this part onward: https://bioconductor.org/packages/devel/bioc/vignettes/EnhancedVolcano/inst/doc/EnhancedVolcano.html#encircle-highlight-certain-variables
Many thanks for your continued help Kevin.
Parhaps I am confised but doesnt 'gold' in
lead to overwiting all of the colours I have already set in lines 1-4 in my last message.
Instead is there a way I can overwirte the positions at which
EMTdbgenes.ord$symbol %in% VolcanoEMTgenes
is true to black .. somthing like(im not very good at base R arguments and would be greatful of some guidance on this)
Yes, there you would just instead need:
This may also work, assuming that you already have set up keyvals.colour with the previous 4 colours / levels:
Then you still have to add the names, which should then not be too difficult.
Thank you Kevin that has worked.