我有一个包含三个数字列的数据框dataInitial
。
Axis1
,Axis2
和Value
。
以下是我对热图图表的代码:
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似乎没有考虑我的排序(参见下图)
欢迎任何想法。
答案 0 :(得分:0)
我不确定为什么(也许有人可以发布更详细的答案,说明为什么有效)但在上面的代码中用breaks
替换limits
效果很好。
谢谢@Phil提示。