This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to mark/ highlights specific points (expression value) in boxplot in R

Hi All,

Sorry for technical question.

I am trying to make a boxplot of gene expression data for some samples, and wanted to highlight specific points (expression value) based on gene name "TP53". I am able to highlight color in scatter plot but couldn't in boxplot, my code for scatter plot is

 plot(datamtx, col=ifelse(rownames(datamtx)=="TP53","red","black"))

I tried similar function for Boxplot but doesn't work..

boxplot(datamtx, labels=ifelse(rownames(datamtx)=="TP53","red","black"))

and

boxplot(datamtx, col=ifelse(rownames(datamtx)=="TP53","red","black"))

please help.

Thanks

r boxplot

1 answer

# Simulate a two column (tumor and normal) data with 10 genes. Gene names as row names
df=data.frame(normal=rnorm(10,60,5), tumor=rnorm(10,70,4))
row.names(df)=paste0("gene_",seq(1:10))
# Draw box plot
boxplot(df)
# Highlight the gene "gene_4" on box plot. Gene names are represented by row names
stripchart(df["gene_4",], vertical = T, method = "jitter", add=T, pch=20, col=as.factor(colnames(df)))

Rplot01

Thanks a lot, @cpad0112

Log in to answer this question.