ggplot 热图图例不代表负数
我正在尝试为包含负数的数据集制作热图:
Ne BR Error
10000 0.00001 1.62
10000 0.000001 -1.03
10000 0.0000001 -0.124
100000 0.00001 36.73
100000 0.000001 5.86
100000 0.0000001 -0.79
1000000 0.00001 -8.335
1000000 0.000001 39.465
1000000 0.0000001 2.59
我使用了以下代码:
library(ggplot2)
data = read.csv('full_path')
(p <- ggplot(data[1:9,], aes(Ne, BR)) +
geom_tile(aes(fill=Error), colour="white") +
scale_fill_gradient(low="white", high="black") + scale_x_log('Ne') +
scale_y_log('Birth Rate') + opts(axis.ticks = theme_blank()))
这会生成一个很好的热图,但图例不考虑负数。颜色似乎正确反映了负值,但图例停在零处,即浅灰色。如何从中获取涵盖数据框“错误”列中全部数据的图例?
I'm trying to make a heat map for a data set that includes negative numbers:
Ne BR Error
10000 0.00001 1.62
10000 0.000001 -1.03
10000 0.0000001 -0.124
100000 0.00001 36.73
100000 0.000001 5.86
100000 0.0000001 -0.79
1000000 0.00001 -8.335
1000000 0.000001 39.465
1000000 0.0000001 2.59
I've used this code:
library(ggplot2)
data = read.csv('full_path')
(p <- ggplot(data[1:9,], aes(Ne, BR)) +
geom_tile(aes(fill=Error), colour="white") +
scale_fill_gradient(low="white", high="black") + scale_x_log('Ne') +
scale_y_log('Birth Rate') + opts(axis.ticks = theme_blank()))
This produces a fine heatmap, but the legend doesn't account for the negative numbers. The colors appear to correctly reflect the negative values, but the legend stops at zero, which is light grey. How can I get a legend out of this that covers the full range of the data in the 'Error' column of my dataframe?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
ggplot
只是试图为您选择比例中的“好的”中断,类似于选择轴刻度线的方式。 (我将您的数据框名称更改为dat
,因为data
是 R 中常用的函数。这不是什么大问题,但可以避免混淆。)Try this:
ggplot
is just trying to pick 'nice' breaks in the scale for you, similarly to how axis tick marks are chosen. (I changed your data frame name todat
, asdata
is a commonly used function in R. It's not a huge deal, but it avoids confusion.)