define color gradient for negative and positive values scale_fill_gradientn()

和自甴很熟 提交于 2019-12-05 13:12:38

You need to specify the limits argument in scale_fill_gradientn:

data.m <- melt(data.clean, id = "Type")
p <- ggplot(data.m, aes(x = variable, y = Type, fill = value) + geom_tile() +
         scale_fill_gradientn(colours=c(bl,"white", re), na.value = "grey98",
         limits = c(-1, 1)) 
p
p %+% transform(data.m, value = abs(value))

Will give the two following graphs:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!