未考虑 ggplot2 中的轴排序

Axis ordering in ggplot2 is not taken into account

我有一个包含三个数字列的数据框 dataInitialAxis1Axis2Value

这是我的热图代码:

theplot <- ggplot(dataInitial, aes(as.factor(Axis1), as.factor(Axis2), group=Axis2))
theplot <- theplot + geom_tile(aes(fill = Value))
theplot <- theplot + geom_text(aes(fill = Value, label = round(Value, 1)))
theplot <- theplot + scale_x_discrete(breaks=sort(unique(dataInitial$Axis1),TRUE))
theplot <- theplot + scale_y_discrete(breaks=sort(unique(dataInitial$Axis2),TRUE))
theplot <- theplot + scale_fill_gradient(low = "red", high = "green") 
theplot <- theplot + theme_bw()

我希望我的轴按降序排序,但 ggplot2 似乎没有考虑我的排序(参见下图)

欢迎提出任何想法。

我不确定为什么(也许有人可以 post 更详细地回答为什么会这样)但是在上面的代码中用 limits 替换 breaks 效果很好。 感谢@Phil 的提示。