[英]Axis ordering in ggplot2 is not taken into account
我有一個包含三個數字列的數據框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似乎沒有考慮到我的排序(參見下圖)
任何想法都歡迎。
我不確定為什么(也許有人可以發布一個更詳細的答案,說明為什么這樣),但是用上面的代碼中的limits
替換breaks
效果很好。 感謝@Phil的提示。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.