heatmap ggplot2颜色渐变(scale_fill_gradient)

use*_*678 3 r heatmap ggplot2

我试图用ggplot2绘制热图,我想调整颜色条的大小并增加字体.

以下是代码的相关部分:

g <- ggplot(data=melt.m)
g2 <- g+geom_rect(aes(xmin=colInd-1, xmax=colInd, 
  ymin=rowInd-1, ymax=rowInd, fill=value))

g2 <- g2+scale_x_continuous('beta', breaks=c(1, ceiling(cols/2), rows)-0.5, 
  labels=c(1,ceiling(cols/2), rows))
g2 <- g2+scale_y_continuous('alpha', breaks=c(1, ceiling(rows/2), rows)-0.5, 
  labels=c(1, ceiling(rows/2), rows))

g2 <- g2+opts(panel.grid.minor=theme_line(colour=NA),
  panel.grid.major=theme_line(colour=NA),
  panel.background=theme_rect(fill=NA, colour=NA), 
  axis.text.x=theme_text(size=30),
  axis.text.y=theme_text(size=30, angle=90), 
  axis.title.x=theme_text(size=30),
  axis.title.y=theme_text(size=30, angle=90), title = title)

heatscale <- c(low='ghostwhite', high='steelblue')

g2 <- g2+scale_fill_gradient("", heatscale[1], heatscale[2], bias = 10)
Run Code Online (Sandbox Code Playgroud)

它工作正常,问题是右侧的颜色图例太小.有没有办法让颜色图例变大,增加图例的字体大小?

谢谢,

KZ

Bri*_*ggs 8

我们没有您的melt.m数据,因此您提供的代码不可重复.但是,使用diamonds附带的数据集ggplot2作为示例:

ggplot(diamonds, aes(x=table, y=price)) +
  geom_bin2d() +
  scale_fill_gradient("", 'ghostwhite', 'steelblue', bias=10) +
  opts(legend.key.width=unit(1, "in"),
       legend.text = theme_text(size=30))
Run Code Online (Sandbox Code Playgroud)

legend.key.width而且legend.text你正在寻找.我使用夸张的尺寸使其更加明显.

ggplot命令的结果

有关可用选项的更多详细信息,请参阅https://github.com/hadley/ggplot2/wiki/+opts%28%29-List