简体   繁体   中英

ggplot scale gradient color in R

I'm new to ggplot and am having issues with the scale_colour_gradient2() function. Whenever I include the argument in the following code, I get an error.

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")   

Thoughts? Thanks.

You are using scale_color_gradient when there's no color to scale. You'll want to use scale_fill_gradient or change fill=value to color=value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM