不考虑ggplot2中的轴排序

时间:2015-05-18 06:42:34

标签: r plot ggplot2 axis heatmap

我有一个包含三个数字列的数据框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似乎没有考虑我的排序(参见下图)

The Plot

欢迎任何想法。

1 个答案:

答案 0 :(得分:0)

我不确定为什么(也许有人可以发布更详细的答案,说明为什么有效)但在上面的代码中用breaks替换limits效果很好。 谢谢@Phil提示。