在heatmap.2中使行标签为斜体. [英] Make row labels italic in heatmap.2

查看:322
本文介绍了在heatmap.2中使行标签为斜体.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用R函数heatmap.2将行标签设置为斜体.没有默认选项,例如,我无法通过设置par(font=3)来解决.如何在heatmap.2中将行标签设置为斜体?

I'm trying to make my row labels italic using the R function heatmap.2. There's no default option and I can't figure out a work around by setting par(font=3) for example. How can I set my row labels to be italic in heatmap.2?

set.seed(123)
data = matrix(sample(100), nrow=10, ncol=10)
rownames(data) = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")

library(gplots)

heatmap.2(data,
           Colv=TRUE,
           Rowv=TRUE,
           xlab=NA,
           ylab=NA)

推荐答案

您可以对heatmap.2使用labCollabRow自变量来传递标签.我们只需要弄清楚如何将它们作为plotmath表达式列表传递即可.我总是觉得这很痛苦,因为我经常记不起来适当的咒语,但通过改编

You can use the labCol and labRow arguments to heatmap.2 to pass in the labels. We just need to figure out how to pass these in as a list of plotmath expressions. I always find this painful, as I don't do it often enough to remember the appropriate incantations, but was able to put the code together by adapting this R-help answer. Note that the matrix needs to have column names, which I've added in the code below

library(gplots)

# Fake data
set.seed(123)
data = matrix(sample(100), nrow=10, ncol=10)
rownames(data) = c("A", "B", "C", "D", "E", "F", "G", "H", "I", "J")
colnames(data) = 1:ncol(data)

heatmap.2(data,
          Colv=TRUE,
          Rowv=TRUE,
          labCol=as.expression(lapply(colnames(data), function(a) bquote(italic(.(a))))),
          labRow=as.expression(lapply(rownames(data), function(a) bquote(italic(.(a))))),
          xlab=NA,
          ylab=NA)

这篇关于在heatmap.2中使行标签为斜体.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆