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?
Try this:
ggplotis 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, asdatais a commonly used function in R. It’s not a huge deal, but it avoids confusion.)