热图 ggplot2 颜色渐变 (scale_fill_gradient)
我正在尝试使用 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)
它工作正常,问题是右侧的颜色图例太小。有没有办法让颜色图例变大并增加图例的字体大小?
谢谢,
kz
I am trying to plot a heat map with ggplot2 and I would like to resize the colorbar and increase the font.
Here is the relevant part of the code:
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)
It works fine, the problem is that the color legend on the right side is too small. Is there a way to make the color legend bigger and increase the font size of the legend?
Thanks,
kz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们没有您的
melt.m
数据,因此您提供的代码无法重现。但以 ggplot2 附带的 Diamonds 数据集为例:legend.key.width
和legend.text
是您正在寻找的。我使用了夸张的尺寸以使其更加明显。有关可用选项的更多详细信息,请参阅 https://github.com/hadley/ggplot2/wiki/+opts%28%29-List
We don't have your
melt.m
data, so the code you give is not reproducible. Using thediamonds
dataset that comes withggplot2
as an example, though:legend.key.width
andlegend.text
are what you are looking for. I have used exaggerated sizes to make it more obvious.For more details on the options available, see https://github.com/hadley/ggplot2/wiki/+opts%28%29-List
我尝试了一下,发现 R 或 ggplot2 在过去四年里发生了变化。它产生了错误:
能够让它与以下内容一起工作:
最初尝试仅更改文本大小,但必须更改密钥大小,否则它会变得不可读。另外,
unit
需要一个用library(grid)
显式加载的库I tried this and found that R or ggplot2 have changed in the last four years. It yielded the error:
Was able to get it to work with the following instead:
Initially tried just changing the text size but had to change the key size with it or it becomes unreadable. Also,
unit
needs a library explicitly loaded withlibrary(grid)