I created below heatmap
for which I used this code:
library(ggplot2)
library(reshape2)
winners_min_expd0 <- matrix(c(NA, 2, 2, 3, NA, 3, 2, 2, NA), nrow=3, ncol=3, byrow = T)
colnames(winners_min_expd0) <- c("homophily","heterophily","preferential")
rownames(winners_min_expd0) <- c("homophily","heterophily","preferential")
melted_min_expd0 <- melt(winners_min_expd0)
colnames(melted_min_expd0) <- c("winning", "looses", "times")
p_min_expd0 <- ggplot(melted_min_expd0, aes(looses, winning)) +
geom_tile(aes(fill = times), colour = "white") +
scale_fill_gradient(low = "white", high = "red") +
ggtitle("Min function, exp decay off") +
scale_y_discrete(limits=c("preferential", "heterophily", "homophily")) +
xlab("(x) looses against (y)") + ylab("(y) winning over (x)")
p_min_expd0
I would like to:
- rescale "times" bar to range
<0:5>
, I understand there are no{0,1,4,5}
values, but I'd like to have this range - make the "times" heat scale discrete, which means one solid color for one number, e.g.
5 = hot red
,4 = red
, etc. (possible duplicate: ggplot2 heatmap with colors for ranged values), ranges like<0,1)
are acceptable, but I prefer single natural numbers on the scale (instead of value ranges) - add a thin grid on the heatmap, so all tiles (including white ones) are separated by it
- change the gray color of NA values to some lighter gray
Help appreciated, as well as shorter code.
Thanks!