I have a data frame, melted_matrix
:
melted_matrix
value IndA IndB Culture Coverage Var1 Var2
1 0.00000000 1 1 Anatolia_Neolithic 9.431 1 1
2 0.02898616 2 1 Anatolia_Neolithic 6.948 2 1
3 0.02514688 3 1 Anatolia_Neolithic 9.765 3 1
4 0.07381144 4 1 Anatolia_Neolithic 1.213 4 1
5 0.17096256 5 1 Anatolia_Neolithic 0.231 5 1
I am happy reordering it by a single level (i.e. Var1 and Var2 for the x and y axes respectively:
hm.palette = colorRampPalette(rev(brewer.pal(11, 'Spectral')), space='Lab')
ggplot(melted_matrix,
aes(x = reorder(IndA, Var1), y = reorder(IndB, Var2), fill = value)) +
geom_tile() +
coord_equal() +
scale_fill_gradientn(colours = hm.palette(100))
I'd like to then reorder them by Culture, and then Coverage. However, if I try add more levels:
ggplot(melted_matrix,
aes(x = reorder(IndA, Var1, Culture, Coverage),
y = reorder(IndB, Var2, Culture, Coverage), fill = value)) +
geom_tile() +
coord_equal() +
scale_fill_gradientn(colours = hm.palette(100))
Error in get(as.character(FUN), mode = "function", envir = envir) : object 'FUN' of mode 'function' was not found
An error is thrown. Is there a way of adding more levels within the ggplot function call, rather then messing about with the data frame?