Is it possible to italicize row names with pheatmap()?
1
3
Entering edit mode
5.2 years ago

Hello!

Is it possible to italicize the text for row names in pheatmap()?

I tried:

pheatmap(hmdf,
    color= (rainbow(96,start=0.0,end=0.74,alpha=1)),
    border_color = NA,
    show_colnames = TRUE,
    show_rownames = TRUE,
    labels_col=paste0(c("control"," "," ", "653"," "," ", "111"," "," ")),
    angle_col=0,
    labels_row=expression(italic(c("ARP3_ARATH", "HF101_ARATH", "PKL_ARATH", "-",
                                   "UPL1_ARATH", "6GPD3_ARATH", "PNSB3_ARATH", 
                                   "FL3H_MALDO", "-", "FL3H_PETCR", "CALS3_ARATH",
                                   "SRP40_YEAST", "ACC1_ARATH", "RBS2_BRANA", "CNGC5_ARATH",
                                   "MPK9_ARATH", "PHYLO_ARATH", "CO1A1_HUMAN", "FB30_ARATH",
                                   "IFRH_ARATH", "PER45_ARATH", "IRE1A_ARATH", "PLST1_ARATH",
                                   "-", "PMTK_ARATH", "SGO2_ARATH", "P2C14_ARATH", "-",
                                   "PSL4_ARATH", "-", "RBS2_BRANA", "VIP1_MOUSE", "RCA_ARATH",
                                   "CA4_ARATH", "G3PA2_ARATH", "BCA1_ARATH", "CB1C_ARATH",
                                   "TEX10_HUMAN", "CB21_SINAL", "CB5_ARATH", "RVE6_ARATH", 
                                   "-", "-", "YQGF_RHOCB", "IAN9_ARATH", "-", "PRO1_NEUCR",
                                   "-", "ASOL_BRANA", "-", "-", "TIR1_ARATH", "BH106_ARATH",
                                   "EGL1_ARATH", "C3H53_ORYSJ", "PIF1_XENLA", "SBT16_ARATH",
                                   "INO1_SESIN", "APR3_ARATH", "GRDP1_ARATH", "APR3_ARATH",
                                   "APR1_ARATH", "SUT33_ARATH", "APR1_ARATH", "-")))

But I just get a continuous string of italicized row names, even if I add \n after each.

Similarly, I tried making an object, call it rnames, comprised of a string of the above row names. This, likewise, does not work.

Any ideas?

Thank you in advance for your time!

David

R RNA-Seq • 9.5k views
ADD COMMENT
0
Entering edit mode

Awesome! Thank you Kevin!

Can I acknowledge you in the appropriate section when we publish this? You have helped me tremendously with a couple of things. Thanks again!

David

ADD REPLY
0
Entering edit mode

Hey David, sure thing, Hope that the reviewers go easy on you, though!

ADD REPLY
0
Entering edit mode

Thanks Kevin, We still have to validate the RNA seq data with qtPCR but I will let you know when we submit... Thanks again!

ADD REPLY
9
Entering edit mode
5.2 years ago

Hey, there are different ways to do this. The long-winded way is to simply convert your gene names to their unicode italic equivalents. Here, I randomly change the first gene to italic-bold:

UNICODE

# create random data
data <- replicate(10, rnorm(10))
rownames(data) <- paste0("GENE", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

# change first gene name
rownames(data)[1] <- "\U1D46E\U1D46C\U1D475\U1D46C \U1D468"

require(pheatmap)
require(RColorBrewer)

pheatmap(data,
  color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  show_rownames = TRUE,
  cluster_cols = TRUE,
  cluster_rows = TRUE,
  scale = "row",
  clustering_distance_rows = "euclidean",
  clustering_distance_cols = "euclidean",
  clustering_method = "complete",
  border_color = FALSE,
  cex = 1.5,
  labels_row = rownames(data))

ddd

NB - note that I was listening to Simon & Garfunkel (Bridge Over Troubled Water)...

---------------------

expression() and bquote()

The better way is more along the lines of what you were doing already:

# create random data
data <- replicate(10, rnorm(10))
rownames(data) <- paste0("GENE", c(1:nrow(data)))
colnames(data) <- paste("Sample", c(1:ncol(data)))

newnames <- lapply(
  rownames(data),
  function(x) bquote(italic(.(x))))

require(pheatmap)
require(RColorBrewer)

pheatmap(data,
  color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(100),
  show_rownames = TRUE,
  cluster_cols = TRUE,
  cluster_rows = TRUE,
  scale = "row",
  clustering_distance_rows = "euclidean",
  clustering_distance_cols = "euclidean",
  clustering_method = "complete",
  border_color = FALSE,
  cex = 1.5,
  labels_row = as.expression(newnames))

tttt

Kevin

ADD COMMENT
0
Entering edit mode

Many thanks for this solution, Kevin!

However, the expression() bquote() method doesn't seem to work for the legend.

newLegend <- lapply(
  c("-2", "-1", "0", "1", "2", "3"),
  function(x) bquote(bold(.(x))))

pheatmap(...
         legend_breaks = c(-2:3),
         legend_labels = as.expression(newLegend))

The columns and rows text are properly turned bold, but the legend text is not bold, it shows the words bold("2"), etc...

Is there any easy way(s) around this?

ADD REPLY

Login before adding your answer.

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