我有一个数据帧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
我很高兴将其重新排序一个级别(即分别针对x和y轴的Var1和Var2:
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))
然后我想按文化和覆盖率对它们重新排序。但是,如果我尝试添加更多级别:
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
引发错误。有没有一种方法可以在ggplot函数调用中添加更多级别,而不是弄乱数据帧?