R中的ggplot比例渐变颜色

时间:2013-06-17 18:34:47

标签: r colors ggplot2

我是ggplot的新手,我遇到了scale_colour_gradient2()函数的问题。每当我在下面的代码中包含参数时,我都会收到错误。

cor_mat <- matrix(sample(rnorm(100), 49), ncol = 7, nrow = 7)
rownames(cor_mat) <- c("H1", "H2", "H3", "H4", "H5", "H6", "H7")
colnames(cor_mat) <- c("H1", "H2", "H3", "H4", "H5", "H6", "H7")
cor_mat_melt <- melt(cor_mat)           

ggplot(cor_mat_melt, aes(X1, X2, fill = value)) + geom_tile() + labs(x = "", y = "") +     scale_colour_gradient2(low = "red", high = "blue")   

思考?感谢。

1 个答案:

答案 0 :(得分:2)

当没有可缩放的颜色时,您正在使用scale_color_gradient。您需要使用scale_fill_gradient或将fill=value更改为color=value

相关问题