Question: I want order the variable in Y axis based on the number of "Zero". Other than, what if I have 20 or more variable?
my data is simple and show in the fig:
I use ggplot2 to draw that, here is my code:
ggplot(data, aes(year, factor(name))) +
geom_tile(aes(fill =value),colour = "white") +
scale_fill_distiller(palette="Spectral",name="value") +
coord_fixed(ratio=1)+
scale_x_continuous(expand = c(0,0))+
scale_x_continuous(expand=c(0,0),
breaks=seq(1990, 2022, by=1)) +
theme_bw()
dput(data) can show all the structure of data. The information display here:
structure(list(year = c(1998, 1999, 2000, 2001, 2002, 2003, 2004,
2005, 2006, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006), name = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), levels = c("c", "b",
"a"), class = "factor"), value = c(0, 0, 0, 0.346651040983634,
0.575355736998419, 0.258813293790067, 0.996722462580923, 0.634714417365377,
0.574420498061632, 0, 0.2, 0.244170435115193, 0.614290360870049,
0.886645071330728, 0.902835323742732, 0.0956880849086607, 0.229170033665038,
0.4679607332906, 0, 0, 0.8, 0.3, 0.0223354578076282, 0.957371777609129,
0.619967737221035, 0.79910708466687, 0.623430562124169)), row.names = c(NA,
27L), class = "data.frame")