I am trying to change the color in a heatmap graph. I want the Yellow, Red color scheme instead of the default Blue-Darkblue.
My code
a=as.matrix(volcano, ncol=ncol(volcano))
row.names(a)= 1:nrow(a)
library(reshape2)
a1 = melt(a)
colnames(a1) = c('X','Y','value')
head(a1)
library(ggplot2)
ggplot(a1,aes(x = X, y = Y)) +
geom_raster(aes(fill = value),interpolate=TRUE) +
scale_colour_gradient2(low="yellow", high="red", guide="colorbar")
I am getting the following output, which I want in a different color scheme. I am not sure on why the last line - scale_colour_gradient
is not working. All other examples here have this line but with geom_tile function.
When you are using fill
in aesthetics, you have to use scale_fill_gradient
for filling with color. When color is specified in aesthetics, you have to use scale_color_gradient
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With