簡體   English   中英

不考慮ggplot2中的軸排序

[英]Axis ordering in ggplot2 is not taken into account

我有一個包含三個數字列的數據框dataInitial Axis1Axis2Value

這是我的熱圖圖形代碼:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM